javamanager/javacaptain/extensionplugins/javacertstore/inc/javacertstore.h
changeset 21 2a9601315dfc
child 25 9ac0a0a7da70
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  JavaCertStore
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef JAVACERTSTORE_H
       
    19 #define JAVACERTSTORE_H
       
    20 
       
    21 #include "commslistener.h"
       
    22 #include "javaosheaders.h"
       
    23 #include "extensionplugininterface.h"
       
    24 #include "javacommonutils.h"
       
    25 #include <vector>
       
    26 #include <string>
       
    27 
       
    28 namespace java
       
    29 {
       
    30 namespace comms
       
    31 {
       
    32 class CommsMessage;
       
    33 }
       
    34 
       
    35 namespace captain
       
    36 {
       
    37 
       
    38 class CoreInterface;
       
    39 
       
    40 #ifdef __SYMBIAN32__
       
    41 const char KFileSeparator = '\\';
       
    42 const char KJavaCertsDir[] = "security\\trustroots\\device\\certificates";
       
    43 const char KJavaCertsStateDir[] = "security\\trustroots\\device\\state";
       
    44 #else //__SYMBIAN32__
       
    45 const char KFileSeparator = '/';
       
    46 const char KJavaCertsDir[] = "security/trustroots/device/certificates";
       
    47 const char KJavaCertsStateDir[] = "security/trustroots/device/state";
       
    48 #endif //__SYMBIAN32__
       
    49 const char KMetadataSuffix[] = ".metadata";
       
    50 const char KStateSuffix[] = ".state";
       
    51 const char KCertSuffix1[] = ".der";
       
    52 const char KCertSuffix2[] = ".cer";
       
    53 const char KOperatorTrustedUsage[] = "1.3.6.1.4.1.42.2.110.2.2.2.1";
       
    54 const char KSupplementaryOperatorTrustedUsage1[] = "1.3.6.1.4.1.42.2.110.2.2.2.4";
       
    55 const char KSupplementaryOperatorTrustedUsage2[] = "1.3.6.1.4.1.42.2.110.2.2.2.5";
       
    56 const char KSupplementaryOperatorTrustedUsage3[] = "1.3.6.1.4.1.42.2.110.2.2.2.6";
       
    57 const char KOperatorDomainName[] = "Operator";
       
    58 const char KOperatorDomainCategory[] = "OPD";
       
    59 const char KIdentifiedThirdPartyTrustedUsage[] = "1.3.6.1.4.1.42.2.110.2.2.2.3";
       
    60 const char KIdentifiedThirdPartyDomainName[] = "IdentifiedThirdParty";
       
    61 const char KIdentifiedThirdPartyDomainCategory[] = "ITPD";
       
    62 const int PEM_FORMAT = 1;
       
    63 const int DER_FORMAT = 2;
       
    64 
       
    65 typedef struct cert_metadata_st
       
    66 {
       
    67     std::string full_path;
       
    68     std::string hash;
       
    69     int state;
       
    70     bool disposable;
       
    71     bool disablable;
       
    72     std::string prot_domain_name;
       
    73     std::string prot_domain_category;
       
    74     // internal flag highlighting
       
    75     // any changes in the metadata
       
    76     bool changes;
       
    77     // the name of the external
       
    78     // file from where the metadata
       
    79     // was read
       
    80     std::string file_name;
       
    81     // the content/data of the certificate
       
    82     std::string data;
       
    83     // size of the certificate
       
    84     long len;
       
    85 } CERT_METADATA;
       
    86 
       
    87 OS_NONSHARABLE_CLASS(JavaCertStore) :  public java::comms::CommsListener,
       
    88         public ExtensionPluginInterface
       
    89 {
       
    90 public:
       
    91     JavaCertStore();
       
    92     virtual ~JavaCertStore();
       
    93 
       
    94     // PluginInterface
       
    95     virtual void startPlugin(CoreInterface* aCore);
       
    96     virtual void stopPlugin();
       
    97 
       
    98     // ExtensionPluginInterface methods
       
    99     virtual java::comms::CommsListener* getCommsListener();
       
   100 
       
   101 protected:
       
   102     // CommsListener methods
       
   103     virtual void processMessage(java::comms::CommsMessage& aMessage);
       
   104 
       
   105 private:
       
   106     void queryCerts(java::comms::CommsMessage& aMessage);
       
   107     void loadCertsMetadata();
       
   108     void loadCertsMetadata(std::string aCertsLocation);
       
   109     void unloadCertsMetadata();
       
   110     bool readMetadataFromFiles(const std::string& certFileName, CERT_METADATA *);
       
   111     void writeMetadataIntoFile(CERT_METADATA * metadata);
       
   112     int encodeState(bool, bool, int);
       
   113     void manageCert(const std::string&, int);
       
   114     std::string readCert(const std::string& certFileName, long *);
       
   115     long replyWithContent(java::comms::CommsMessage& aReplyMessage, const CERT_METADATA&, int format = DER_FORMAT);
       
   116     void assignProtectionDomain(std::vector<std::string>, CERT_METADATA *);
       
   117     void addCertMetadataToCache(CERT_METADATA* metadata, bool overwrite);
       
   118     bool mkDirAll(const char* dirPath);
       
   119 
       
   120 private:
       
   121     CoreInterface* iCore;
       
   122     std::string iPrimaryCertsPath;
       
   123     std::string iSecondaryCertsPath;
       
   124     std::string iCertsMetadataPath;
       
   125     int no_certs;
       
   126     std::vector<CERT_METADATA*> iCertsMetadata;
       
   127 };
       
   128 
       
   129 } // namespace captain
       
   130 } // namespace java
       
   131 
       
   132 #endif // JAVACERTSTORE_H
       
   133