SOL9 2.0 Sample: CryptMsgSignerInfo

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * CryptMsgSignerInfo.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/03/25 This is a simple program to use SOL::SignedObject class and query 
// method call of the class.
// The query methdod returns handles for SOL::CertStore and SOL::CryptMsg.


#include <sol/crypt/SignedObject.h>
#include <sol/crypt/X509ASNDecoder.h>
#include <sol/crypt/CryptMsgSignerInfo.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 get a counterSignerInfo from signerInfo\n"));

                CryptMsgSignerInfo signerInfo(pSignerInfo);
                CryptMsgSignerInfo counterSigner;

                if (signerInfo.getCounterSignerInfo(counterSigner) == NO_ERROR) {
                    _tprintf(_T("7 OK, signerInfo.getCounterSignerInfo()\n"));
                    SYSTEMTIME st;
                    _tprintf(_T("8 Try to get SigningTime from counterSignerInfo\n"));

                    if (counterSigner.getSigningTime(st) == NO_ERROR) {

                        _tprintf(_T("9 OK, signingTime : %04d/%02d/%02d %02d:%02d\n"),

                                                    st.wYear,
                                                    st.wMonth,
                                                    st.wDay,
                                                    st.wHour,
                                                st.wMinute);
                    } else {
                        _tprintf(_T("10 Failed in counterSigner.getSigningTime()\n"));
                    }

                } else {
                    _tprintf(_T("11 Failed signerInfo.getCounterSignerInfo()\n"));

                }
            } else {
                _tprintf(_T("12 Failed in cryptMsg.getSignerInfo() %x\n"), GetLastError());

            }

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


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

Last modified: 11 Nov 2009

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