Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Renew a DigiCert Certificate from an EST-enabled profile

Demonstrates how to renew a certificate from an EST-enabled profile in DigiCert​​®​​ Trust Lifecycle Manager. (The certificate must be within the renewal window configured in the certificate profile. The CSR must have same Subject DN values as the original certificate.)

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Variant vFortuna
    Handle hoFortuna
    String sEntropy
    Boolean iSuccess
    Handle hoEc
    Variant vPrivKey
    Handle hoPrivKey
    Handle hoCsr
    Variant vBdCsr
    Handle hoBdCsr
    Handle hoHttp
    Variant vTlsClientCert
    Handle hoTlsClientCert
    Variant vBdTlsClientCertPrivKey
    Handle hoBdTlsClientCertPrivKey
    Variant vTlsClientCert
PrivKey    Handle hoTlsClientCertPrivKey
    Variant vResp
    Handle hoResp
    Handle hoMyNewCert
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // The example below duplicates the following OpenSSL commands:
    // 
    // # Name of certificate as argument 1
    // 
    // # Make new key
    // openssl ecparam -name prime256v1 -genkey -noout -out ${1}.key.pem
    // 
    // # Make csr
    // openssl req -new -sha256 -key ${1}.key.pem -out ${1}.p10.csr -subj "/CN=${1}"
    // 
    // # Request new cert
    // curl -v --cacert data/ca.pem --cert data/${1}.pem --key data/${1}.key.pem 
    //     --data-binary @${1}.p10.csr -o ${1}.p7.b64 -H "Content-Type: application/pkcs10" https://clientauth.demo.one.digicert.com/.well-known/est/IOT/simplereenroll
    // 
    // # Convert to PEM
    // openssl base64 -d -in ${1}.p7.b64 | openssl pkcs7 -inform DER -outform PEM -print_certs -out ${1}.pem

    // ------------------------------------------------------------------------------------------------------------------

    // Create a Fortuna PRNG and seed it with system entropy.
    // This will be our source of random data for generating the ECC private key.
    Get Create (RefClass(cComChilkatPrng)) To hoFortuna
    If (Not(IsComObjectCreated(hoFortuna))) Begin
        Send CreateComObject of hoFortuna
    End
    Get ComGetEntropy Of hoFortuna 32 "base64" To sEntropy
    Get ComAddEntropy Of hoFortuna sEntropy "base64" To iSuccess

    Get Create (RefClass(cComChilkatEcc)) To hoEc
    If (Not(IsComObjectCreated(hoEc))) Begin
        Send CreateComObject of hoEc
    End

    // Generate a random EC private key on the prime256v1 curve.
    Get pvComObject of hoFortuna to vFortuna
    Get ComGenEccKey Of hoEc "prime256v1" vFortuna To vPrivKey
    If (IsComObject(vPrivKey)) Begin
        Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
        Set pvComObject Of hoPrivKey To vPrivKey
    End
    Get ComLastMethodSuccess Of hoEc To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoEc To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Create the CSR object and set properties.
    Get Create (RefClass(cComChilkatCsr)) To hoCsr
    If (Not(IsComObjectCreated(hoCsr))) Begin
        Send CreateComObject of hoCsr
    End

    // Specify your CN
    Set ComCommonName Of hoCsr To "mysubdomain.mydomain.com"

    // Create the CSR using the private key.
    Get Create (RefClass(cComChilkatBinData)) To hoBdCsr
    If (Not(IsComObjectCreated(hoBdCsr))) Begin
        Send CreateComObject of hoBdCsr
    End
    Get pvComObject of hoBdCsr to vBdCsr
    Get ComGenCsrBd Of hoCsr vPrivKey vBdCsr To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCsr To sTemp1
        Showln sTemp1
        Send Destroy of hoPrivKey
        Procedure_Return
    End

    // Save the private key and CSR to files.
    Get ComSavePkcs8EncryptedPemFile Of hoPrivKey "password" "c:/temp/qa_output/ec_privkey.pem" To iSuccess
    Send Destroy of hoPrivKey
    Get ComWriteFile Of hoBdCsr "c:/temp/qa_output/csr.pem" To iSuccess

    // ----------------------------------------------------------------------
    // Now do the CURL request to POST the CSR and get the new certificate.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatCert)) To hoTlsClientCert
    If (Not(IsComObjectCreated(hoTlsClientCert))) Begin
        Send CreateComObject of hoTlsClientCert
    End
    Get ComLoadFromFile Of hoTlsClientCert "data/myTlsClientCert.pem" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoTlsClientCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatBinData)) To hoBdTlsClientCertPrivKey
    If (Not(IsComObjectCreated(hoBdTlsClientCertPrivKey))) Begin
        Send CreateComObject of hoBdTlsClientCertPrivKey
    End
    Get ComLoadFile Of hoBdTlsClientCertPrivKey "data/myTlsClientCert.key.pem" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load data/myTlsClientCert.key.pem"
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatPrivateKey)) To hoTlsClientCertPrivKey
    If (Not(IsComObjectCreated(hoTlsClientCertPrivKey))) Begin
        Send CreateComObject of hoTlsClientCertPrivKey
    End
    Get pvComObject of hoBdTlsClientCertPrivKey to vBdTlsClientCertPrivKey
    Get ComLoadAnyFormat Of hoTlsClientCertPrivKey vBdTlsClientCertPrivKey "" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoTlsClientCertPrivKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoTlsClientCertPrivKey to vTlsClientCertPrivKey
    Get ComSetPrivateKey Of hoTlsClientCert vTlsClientCertPrivKey To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoTlsClientCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoTlsClientCert to vTlsClientCert
    Get ComSetSslClientCert Of hoHttp vTlsClientCert To iSuccess

    Set ComRequireSslCertVerify Of hoHttp To True

    // The body of the HTTP request contains the binary CSR.
    Get pvComObject of hoBdCsr to vBdCsr
    Get ComPBinaryBd Of hoHttp "POST" "https://clientauth.demo.one.digicert.com/.well-known/est/IOT/simplereenroll" vBdCsr "application/pkcs10" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComStatusCode Of hoResp To iTemp1
        Showln "response status code = " iTemp1
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed"
        Send Destroy of hoResp
        Procedure_Return
    End

    // The response is the Base64 DER of the new certificate.
    Get Create (RefClass(cComChilkatCert)) To hoMyNewCert
    If (Not(IsComObjectCreated(hoMyNewCert))) Begin
        Send CreateComObject of hoMyNewCert
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoadFromBase64 Of hoMyNewCert sTemp1 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMyNewCert To sTemp1
        Showln sTemp1
        Get ComBodyStr Of hoResp To sTemp1
        Showln "Cert data = " sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp
    Get ComSaveToFile Of hoMyNewCert "c:/temp/qa_output/myNewCert.cer" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMyNewCert To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    Showln "Success."


End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.