omadrm/drmengine/roap/src/JoinDomainReq.cpp
changeset 0 95b198f216e5
child 12 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include "base64.h"
       
    23 #include "JoinDomainReq.h"
       
    24 #include "RoapDef.h"
       
    25 
       
    26 using namespace Roap;
       
    27 
       
    28 // LOCAL CONSTANTS AND MACROS
       
    29 _LIT8(KReqHeader, "<roap:joinDomainRequest xmlns:roap=\"urn:oma:bac:dldrm:roap-1.0\"");
       
    30 _LIT8(KReqNonceTrigger, " triggerNonce=\"");
       
    31 _LIT8(KReqNonceTriggerEnd, "\"");
       
    32 _LIT8(KReqHeaderEnd, ">");
       
    33 _LIT8(KReqNonce, "<nonce>");
       
    34 _LIT8(KReqNonceEnd, "</nonce>");
       
    35 _LIT8(KReqTime, "<time>");
       
    36 _LIT8(KReqTimeEnd, "</time>");
       
    37 _LIT8(KReqDeviceId, "<deviceID><keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    38  algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>");
       
    39 _LIT8(KReqDeviceIdEnd, "</hash></keyIdentifier></deviceID>");
       
    40 _LIT8(KReqRiId, "<riID><keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    41  algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>");
       
    42 _LIT8(KReqRiIdEnd, "</hash></keyIdentifier></riID>");
       
    43 _LIT8(KReqDomainId, "<domainID>");
       
    44 _LIT8(KReqDomainIdEnd, "</domainID>");
       
    45 _LIT8(KReqCertChain, "<certificateChain>");
       
    46 _LIT8(KReqCert, "<certificate>");
       
    47 _LIT8(KReqCertEnd, "</certificate>");
       
    48 _LIT8(KReqCertChainEnd, "</certificateChain>");
       
    49 _LIT8(KReqExtensions, "<extensions>");
       
    50 _LIT8(KReqExtensionsEnd, "</extensions>");
       
    51 _LIT8(KReqPeerKey, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    52  xsi:type=\"roap:PeerKeyIdentifier\">\
       
    53 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>");
       
    54 _LIT8(KReqPeerKeyEnd, "</hash></identifier></extension>");
       
    55 _LIT8(KReqNoOcspResponse, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    56  xsi:type=\"roap:NoOCSPResponse\"></extension>");
       
    57 _LIT8(KReqOcspResponderKeyId, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    58  xsi:type=\"roap:OCSPResponderKeyIdentifier\">\
       
    59 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>");
       
    60 _LIT8(KReqOcspResponderKeyIdEnd, "</hash></identifier></extension>");
       
    61 _LIT8(KReqHashChainSupport, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    62  xsi:type=\"roap:HashChainSupport\"></extension>");
       
    63 _LIT8(KReqSig, "<signature>");
       
    64 _LIT8(KReqSigEnd, "</signature></roap:joinDomainRequest>");
       
    65 
       
    66 // ============================ MEMBER FUNCTIONS ===============================
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CJoinDomainReq::CJoinDomainReq
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CJoinDomainReq::CJoinDomainReq():
       
    75     iDomainId(NULL),
       
    76     iOcspResponderKeyId(NULL),
       
    77     iSignature(NULL),
       
    78     iTriggerNonce(NULL)
       
    79     {
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CJoinDomainReq::ConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CJoinDomainReq::ConstructL()
       
    88     {
       
    89     iTime.UniversalTime();
       
    90     iPeerKeyIdentifier.SetLength(0);
       
    91     iOcspInfoStored = EFalse;
       
    92     iHashChainSupport = ETrue;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CJoinDomainReq::NewL
       
    97 // Two-phased constructor.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CJoinDomainReq* CJoinDomainReq::NewL()
       
   101     {
       
   102     CJoinDomainReq* self = new( ELeave ) CJoinDomainReq;
       
   103     
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL();
       
   106     CleanupStack::Pop();
       
   107 
       
   108     return self;
       
   109     }
       
   110 
       
   111     
       
   112 // Destructor
       
   113 CJoinDomainReq::~CJoinDomainReq()
       
   114     {
       
   115     iCertificateChain.ResetAndDestroy();
       
   116     delete iDomainId;
       
   117     delete iSignature;
       
   118     delete iTriggerNonce;
       
   119     delete iOcspResponderKeyId;
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CJoinDomainReq::?member_function
       
   125 // ?implementation_description
       
   126 // (other items were commented in a header).
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 HBufC8* CJoinDomainReq::MessageAsXmlL(void)
       
   130     {
       
   131     HBufC8* r = NULL;
       
   132     CBufFlat* b = NULL;
       
   133     TInt i;
       
   134 
       
   135     b = CBufFlat::NewL(128);
       
   136     CleanupStack::PushL(b);
       
   137     BufAppendL(b, KReqHeader);
       
   138     if (iTriggerNonce)
       
   139         {
       
   140         BufAppendL(b, KReqNonceTrigger);
       
   141         BufAppendL(b, *iTriggerNonce);
       
   142         BufAppendL(b, KReqNonceTriggerEnd);
       
   143         }
       
   144     BufAppendL(b, KReqHeaderEnd);
       
   145 
       
   146     BufAppendL(b, KReqDeviceId);
       
   147     BufAppendBase64L(b, iDeviceId);
       
   148     BufAppendL(b, KReqDeviceIdEnd);
       
   149 
       
   150     BufAppendL(b, KReqRiId);
       
   151     BufAppendBase64L(b, iRiId);
       
   152     BufAppendL(b, KReqRiIdEnd);
       
   153 
       
   154     BufAppendL(b, KReqNonce);
       
   155     BufAppendBase64L(b, iNonce);
       
   156     BufAppendL(b, KReqNonceEnd);
       
   157 
       
   158     BufAppendL(b, KReqTime);
       
   159     BufAppendTimeL(b, iTime);
       
   160     BufAppendL(b, KReqTimeEnd);
       
   161 
       
   162     BufAppendL(b, KReqDomainId);
       
   163     BufAppendL(b, *iDomainId);
       
   164     BufAppendL(b, KReqDomainIdEnd);
       
   165 
       
   166     if (iCertificateChain.Count() > 0)
       
   167         {
       
   168         BufAppendL(b, KReqCertChain);
       
   169         for (i = 0; i < iCertificateChain.Count(); i++)
       
   170             {
       
   171             BufAppendL(b, KReqCert);
       
   172             BufAppendBase64L(b, *iCertificateChain[i]);
       
   173             BufAppendL(b, KReqCertEnd);
       
   174             }
       
   175         BufAppendL(b, KReqCertChainEnd);
       
   176         }
       
   177         
       
   178     if (iPeerKeyIdentifier.Length() ||
       
   179         iOcspResponderKeyId ||
       
   180         iOcspInfoStored ||
       
   181         iHashChainSupport)
       
   182         {
       
   183         BufAppendL(b, KReqExtensions);
       
   184         }
       
   185         
       
   186     if (iPeerKeyIdentifier.Length())
       
   187         {
       
   188         BufAppendL(b, KReqPeerKey);
       
   189         BufAppendBase64L(b, iPeerKeyIdentifier);
       
   190         BufAppendL(b, KReqPeerKeyEnd);
       
   191         }
       
   192         
       
   193     if (iOcspInfoStored)
       
   194         {
       
   195         BufAppendL(b, KReqNoOcspResponse);
       
   196         }
       
   197         
       
   198     if (iOcspResponderKeyId)
       
   199         {
       
   200         BufAppendL(b, KReqOcspResponderKeyId);
       
   201         BufAppendBase64L(b, *iOcspResponderKeyId);
       
   202         BufAppendL(b, KReqOcspResponderKeyIdEnd);
       
   203         }
       
   204 
       
   205     if (iHashChainSupport)
       
   206         {
       
   207         BufAppendL(b, KReqHashChainSupport);
       
   208         }
       
   209                
       
   210     if (iPeerKeyIdentifier.Length() ||
       
   211         iOcspResponderKeyId ||
       
   212         iOcspInfoStored ||
       
   213         iHashChainSupport)
       
   214         {
       
   215         BufAppendL(b, KReqExtensionsEnd);
       
   216         }
       
   217 
       
   218     BufAppendL(b, KReqSig);
       
   219     BufAppendL(b, KReqSigEnd);
       
   220 
       
   221     r = b->Ptr(0).AllocL();
       
   222     CleanupStack::PopAndDestroy(b);
       
   223     return r;
       
   224     }