Unicode C
Unicode C
Sign PDF using ARSS (Aruba Remote Signing Service)
See more Signing in the Cloud Examples
Demonstrates how to digitally sign a PDF using the Aruba Remote Signing Service (ARSS).
The example loads a local PDF and certificate, configures the ARSS cloud signer credentials,
specifies the OTP authentication type with typeOtpAuth, and creates an
LTV-enabled signed PDF where the private key remains protected on the Aruba signing server.
Chilkat Unicode C Downloads
#include <C_CkPdfW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkCertW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdfW pdf;
HCkJsonObjectW json;
HCkCertW cert;
HCkJsonObjectW jsonArss;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pdf = CkPdfW_Create();
// Load the PDF that will be digitally signed.
success = CkPdfW_LoadFile(pdf,L"qa_data/pdf/hello.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
return;
}
// Signing options are specified in a JSON object.
json = CkJsonObjectW_Create();
// Enable LTV (Long-Term Validation).
// When ltvOcsp is true, OCSP validation information is embedded in the PDF
// so that signature validation can continue to succeed in the future,
// even if the original OCSP responder is no longer available.
CkJsonObjectW_UpdateBool(json,L"ltvOcsp",TRUE);
// Specify the visual appearance of the signature on the PDF page.
CkJsonObjectW_UpdateInt(json,L"page",1);
CkJsonObjectW_UpdateString(json,L"appearance.y",L"top");
CkJsonObjectW_UpdateString(json,L"appearance.x",L"left");
CkJsonObjectW_UpdateString(json,L"appearance.fontScale",L"10.0");
// Text lines displayed in the visible signature appearance.
// Special values such as "cert_cn" and "current_dt" are replaced
// with the certificate common name and current date/time.
CkJsonObjectW_UpdateString(json,L"appearance.text[0]",L"Digitally signed by: cert_cn");
CkJsonObjectW_UpdateString(json,L"appearance.text[1]",L"current_dt");
CkJsonObjectW_UpdateString(json,L"appearance.text[2]",L"This is an LTV-enabled signature.");
// Load the signing certificate.
//
// The private key is NOT stored locally. Instead, the private key is
// stored and protected on the Aruba Remote Signing Service (ARSS).
//
// Even though the signing operation will occur remotely, Chilkat still
// needs the corresponding public certificate locally so that it can
// construct the CMS/PAdES signature and embed the certificate chain
// in the signed PDF.
cert = CkCertW_Create();
success = CkCertW_LoadFromFile(cert,L"qa_data/certs/myCert.cer");
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
return;
}
// Configure Aruba Remote Signing Service (ARSS) credentials.
//
// When SetCloudSigner is called, Chilkat is instructed to perform
// cryptographic signing operations through the ARSS web service.
// The PDF is assembled locally, but the actual RSA signature operation
// is performed remotely using the private key held by Aruba.
jsonArss = CkJsonObjectW_Create();
// Required. Indicates that the cloud signing provider is ARSS.
CkJsonObjectW_UpdateString(jsonArss,L"service",L"ARSS");
// The ARSS certificate identifier (for example, "AS0").
// This identifies which remote certificate/private key pair should be used.
// The remote certificate should correspond to the certificate loaded above.
CkJsonObjectW_UpdateString(jsonArss,L"certID",L"YOUR_ARSS_CERT_ID");
// OTP password associated with the Aruba remote-signing account.
// Depending on the ARSS configuration, an OTP may be required to
// authorize each signing operation.
CkJsonObjectW_UpdateString(jsonArss,L"otpPwd",L"YOUR_OTP_PWD");
// Specifies the OTP authentication environment.
//
// Common values are:
// "demoprod" - Demo/Test environment
// "prod" - Production environment
//
// This value is sent to the ARSS service and determines how the OTP
// authentication is validated. The correct value depends on the type
// of Aruba account and environment that has been provisioned.
//
// If signing fails with an authentication-related error, verify that
// the typeOtpAuth value matches the environment associated with the
// ARSS account credentials being used.
CkJsonObjectW_UpdateString(jsonArss,L"typeOtpAuth",L"demoprod");
// ARSS account username.
CkJsonObjectW_UpdateString(jsonArss,L"user",L"YOUR_ARSS_USERNAME");
// ARSS account password.
CkJsonObjectW_UpdateString(jsonArss,L"userPWD",L"YOUR_ARSS_PASSWORD");
// Beginning with Chilkat v11.5.0, the ARSS endpoint can be explicitly
// specified. This allows the application to target a particular
// Aruba signing service endpoint when required.
CkJsonObjectW_UpdateString(jsonArss,L"endpoint",L"https://app1.firma-remota.it/ArubaSignerService/webresources/signerservice");
success = CkCertW_SetCloudSigner(cert,jsonArss);
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
CkJsonObjectW_Dispose(jsonArss);
return;
}
// Associate the certificate with the PDF object.
// All subsequent signing operations will use this certificate.
success = CkPdfW_SetSigningCert(pdf,cert);
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
CkJsonObjectW_Dispose(jsonArss);
return;
}
// Create the signed PDF.
//
// Chilkat performs all PDF processing locally. When the time comes
// to generate the cryptographic signature value, Chilkat sends the
// hash to ARSS, which signs it using the remote private key and returns
// the signature. The private key never leaves the Aruba service.
success = CkPdfW_SignPdf(pdf,json,L"qa_output/hello_ltv_signed.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
CkJsonObjectW_Dispose(jsonArss);
return;
}
wprintf(L"The PDF has been successfully cryptographically signed with long-term validation.\n");
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
CkJsonObjectW_Dispose(jsonArss);
}