SOL9 Sample: CertSignerInfoDialog

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * CertSignerInfoDialog.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/03/26 This is a simple program to use SOL::SignedObject class and CertSignerInfoDialog class
// 

#include <sol/crypt/SignedObject.h>
#include <sol/crypt/X509ASNDecoder.h>
#include <sol/crypt/CryptMsgSignerInfo.h>
#include <sol/crypt/CertSignerInfoDialog.h>


void _tmain(int argc, TCHAR** argv)
{
  if (argc != 2) {
    _tprintf(_T("Usage:\n%s program.exe or some.dll\n"), argv[0]);
    return;  
  }

  if (GetFileAttributes(argv[1]) == 0xffffffff) {
    _tprintf(_T("File not found:%s\n"), argv[1]);
    return;
  }

  try {
    //Signed Object

    SignedObject signedObject(argv[1]);

    CertStore certStore;
    CryptMsg  cryptMsg;

    //Query a certificate from the file of fileName

    _tprintf(_T("1 Try to signedObject.query(certStore, cryptMsg) %s\n"), argv[1]);

    if (signedObject.query(certStore, cryptMsg) == NO_ERROR) {

      _tprintf(_T("2 OK, signedObject.query().\n Got a certStore and a cryptMsg %s\n"), argv[1]);
      PCMSG_SIGNER_INFO pSignerInfo = NULL;

      _tprintf(_T("3 Tryt to getSignerInfo from cryptMsg\n"));

      if (cryptMsg.getSignerInfo(&pSignerInfo) == NO_ERROR) {
        _tprintf(_T("4 OK, cryptMsg.getSignerInfo()\n"));
        
        X509ASNDecoder decoder;
        String issuer = _T("");
        decoder.toString(pSignerInfo->Issuer, issuer);

        _tprintf(_T("5 SignerInfo Issuer:%s\n"), (const TCHAR*)issuer);


        _tprintf(_T("6 Tryt to show a CertSignerInfoDialog for the pSignerInfo\n"));

        CryptMsgSignerInfo signerInfo(pSignerInfo);

        CertSignerInfoDialog signerInfoDialog;

        if (signerInfoDialog.show(pSignerInfo, cryptMsg.getCryptMsg()) == NO_ERROR) {
          _tprintf(_T("7 OK, signerInfoDialog.show()\n"));
        } else {
          _tprintf(_T("8 Failed in signerInfoDialog.show()\n"));
        }
      } else {
        _tprintf(_T("9 Failed in cryptMsg.getSignerInfo()\n"));

      }
    } else {
      _tprintf(_T("10 Failed to signedObjec.query().\n '%s' is not signed\n"), argv[1]);
    }

  } catch (...) {
    printf("11 Exception %x\n", GetLastError());
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.