secureswitools/swisistools/source/sisxlibrary/sissignaturealgorithm.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file 
       
    21  @internalComponent
       
    22  @released
       
    23 */
       
    24 
       
    25 #include <openssl/pem.h>
       
    26 #include <openssl/dsa.h>
       
    27 #include <openssl/rsa.h>
       
    28 #include <openssl/err.h>
       
    29 #include <openssl/bio.h>
       
    30 
       
    31 #include <iostream>
       
    32 #include <fstream>
       
    33 #include <string>
       
    34 
       
    35 
       
    36 #include "sissignaturealgorithm.h"
       
    37 #include "utility.h"
       
    38 #include "utility_interface.h"
       
    39 
       
    40 
       
    41 #define RSA_IDENTIFIER				L"1.2.840.113549.1.1.5"
       
    42 #define DSA_IDENTIFIER				L"1.2.840.10040.4.3"
       
    43 #define DSA_PRIME_SIZE				1024
       
    44 #define OLD_PEM_FORMAT_TAG			"Proc-Type"
       
    45 #define ENCRYPTION_ALGORITHM_TAG	"DEK-Info"
       
    46 #define PEM_HEADER					"----"
       
    47 
       
    48 
       
    49 void CSISSignatureAlgorithm::SetAlgorithm (const TAlgorithm aAlgorithm)
       
    50 	{
       
    51 	switch (aAlgorithm)
       
    52 		{
       
    53 	case EAlgRSA :
       
    54 		iAlgorithmIdentifier = RSA_IDENTIFIER;
       
    55 		break;
       
    56 	case EAlgDSA :
       
    57 		iAlgorithmIdentifier = DSA_IDENTIFIER;
       
    58 		break;
       
    59 	default :
       
    60 		throw CSISException (CSISException::EIllegal, L"Bad signature algorithm");
       
    61 		}
       
    62 	iAlgorithm = aAlgorithm;
       
    63 	}
       
    64 
       
    65 CSISSignatureAlgorithm::TAlgorithm CSISSignatureAlgorithm::Algorithm ()	const
       
    66 	{
       
    67 	if ((iAlgorithm == EAlgNone) && ! iAlgorithmIdentifier.empty ())
       
    68 		{
       
    69 		if (iAlgorithmIdentifier == RSA_IDENTIFIER)
       
    70 			{
       
    71 			iAlgorithm = EAlgRSA;
       
    72 			}
       
    73 		else
       
    74 		if (iAlgorithmIdentifier == DSA_IDENTIFIER)
       
    75 			{
       
    76 			iAlgorithm = EAlgDSA;
       
    77 			}
       
    78 		else
       
    79 			{
       
    80 			throw CSISException (CSISException::EIllegal, L"Bad signature algorithm");
       
    81 			}
       
    82 		}
       
    83 	return iAlgorithm;
       
    84 	}
       
    85 
       
    86 
       
    87 void CSISSignatureAlgorithm::Verify (const TUint32 aLanguages) const
       
    88 	{
       
    89 	CStructure <CSISFieldRoot::ESISSignatureAlgorithm>::Verify (aLanguages);
       
    90 	if (	(iAlgorithmIdentifier != RSA_IDENTIFIER) &&
       
    91 			(iAlgorithmIdentifier != DSA_IDENTIFIER))
       
    92 
       
    93 		{
       
    94 		throw CSISException (CSISException::EIllegal, L"Bad signature algorithm");
       
    95 		}
       
    96 	}