Bug Summary

File:libxmlsec/unxlngi6.pro/misc/build/xmlsec1-1.2.14/src/nss/pkikeys.c
Location:line 757, column 5
Description:Value stored to 'handle' is never read

Annotated Source Code

1/**
2 * XMLSec library
3 *
4 * This is free software; see Copyright file in the source
5 * distribution for preciese wording.
6 *
7 * Copyright (c) 2003 America Online, Inc. All rights reserved.
8 */
9#include "globals.h"
10
11#include <string.h>
12
13#include <pk11func.h>
14#include <keyhi.h>
15#include <pk11pqg.h>
16
17#include <xmlsec/xmlsec.h>
18#include <xmlsec/xmltree.h>
19#include <xmlsec/keys.h>
20#include <xmlsec/keyinfo.h>
21#include <xmlsec/transforms.h>
22#include <xmlsec/errors.h>
23
24#include <xmlsec/nss/crypto.h>
25#include <xmlsec/nss/bignum.h>
26#include <xmlsec/nss/pkikeys.h>
27#include <xmlsec/nss/tokens.h>
28
29/**************************************************************************
30 *
31 * Internal NSS PKI key CTX
32 *
33 *************************************************************************/
34typedef struct _xmlSecNssPKIKeyDataCtx xmlSecNssPKIKeyDataCtx,
35 *xmlSecNssPKIKeyDataCtxPtr;
36struct _xmlSecNssPKIKeyDataCtx {
37 SECKEYPublicKey *pubkey;
38 SECKEYPrivateKey *privkey;
39};
40
41/******************************************************************************
42 *
43 * PKI key (dsa/rsa)
44 *
45 * xmlSecNssPKIKeyDataCtx is located after xmlSecTransform
46 *
47 *****************************************************************************/
48#define xmlSecNssPKIKeyDataSize(sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx)) \
49 (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx))
50#define xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
\
51 ((xmlSecNssPKIKeyDataCtxPtr)(((xmlSecByteunsigned char*)(data)) + sizeof(xmlSecKeyData)))
52
53
54static int xmlSecNssPKIKeyDataInitialize (xmlSecKeyDataPtr data);
55static void xmlSecNssPKIKeyDataFinalize (xmlSecKeyDataPtr data);
56
57
58static void xmlSecNSSPKIKeyDataCtxFree (xmlSecNssPKIKeyDataCtxPtr ctx);
59static int xmlSecNSSPKIKeyDataCtxDup (xmlSecNssPKIKeyDataCtxPtr ctxDst,
60 xmlSecNssPKIKeyDataCtxPtr ctxSrc);
61static int xmlSecNssPKIKeyDataAdoptKey (xmlSecKeyDataPtr data,
62 SECKEYPrivateKey *privkey,
63 SECKEYPublicKey *pubkey);
64
65
66static int
67xmlSecNssPKIKeyDataInitialize(xmlSecKeyDataPtr data) {
68 xmlSecNssPKIKeyDataCtxPtr ctx;
69
70 xmlSecAssert2(xmlSecKeyDataIsValid(data), -1)if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",70,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
(-1); }
;
71 xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",71,__FUNCTION__, ((void*)0
), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return(-1); }
;
72
73 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
74 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",74,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
75
76 memset(ctx, 0, sizeof(xmlSecNssPKIKeyDataCtx));
77
78 return(0);
79}
80
81
82static void
83xmlSecNssPKIKeyDataFinalize(xmlSecKeyDataPtr data) {
84 xmlSecNssPKIKeyDataCtxPtr ctx;
85
86 xmlSecAssert(xmlSecKeyDataIsValid(data))if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",86,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
; }
;
87 xmlSecAssert(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",87,__FUNCTION__, ((void*)0
), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return; }
;
88
89 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
90 xmlSecAssert(ctx != NULL)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",90,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return; }
;
91
92 xmlSecNSSPKIKeyDataCtxFree(ctx);
93 memset(ctx, 0, sizeof(xmlSecNssPKIKeyDataCtx));
94}
95
96
97static void
98xmlSecNSSPKIKeyDataCtxFree(xmlSecNssPKIKeyDataCtxPtr ctx)
99{
100 xmlSecAssert(ctx != NULL)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",100,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return; }
;
101 if (ctx->privkey != NULL((void*)0)) {
102 SECKEY_DestroyPrivateKey(ctx->privkey);
103 ctx->privkey = NULL((void*)0);
104 }
105
106 if (ctx->pubkey)
107 {
108 SECKEY_DestroyPublicKey(ctx->pubkey);
109 ctx->pubkey = NULL((void*)0);
110 }
111
112}
113
114static int
115xmlSecNSSPKIKeyDataCtxDup(xmlSecNssPKIKeyDataCtxPtr ctxDst,
116 xmlSecNssPKIKeyDataCtxPtr ctxSrc)
117{
118 xmlSecNSSPKIKeyDataCtxFree(ctxDst);
119 ctxDst->privkey = NULL((void*)0) ;
120 ctxDst->pubkey = NULL((void*)0) ;
121 if (ctxSrc->privkey != NULL((void*)0)) {
122 ctxDst->privkey = SECKEY_CopyPrivateKey(ctxSrc->privkey);
123 if(ctxDst->privkey == NULL((void*)0)) {
124 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",124,__FUNCTION__,
125 NULL((void*)0),
126 "SECKEY_CopyPrivateKey",
127 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
128 "error code=%d", PORT_GetError());
129 return(-1);
130 }
131 }
132
133 if (ctxSrc->pubkey != NULL((void*)0)) {
134 ctxDst->pubkey = SECKEY_CopyPublicKey(ctxSrc->pubkey);
135 if(ctxDst->pubkey == NULL((void*)0)) {
136 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",136,__FUNCTION__,
137 NULL((void*)0),
138 "SECKEY_CopyPublicKey",
139 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
140 "error code=%d", PORT_GetError());
141 return(-1);
142 }
143 }
144 return (0);
145}
146
147static int
148xmlSecNssPKIKeyDataAdoptKey(xmlSecKeyDataPtr data,
149 SECKEYPrivateKey *privkey,
150 SECKEYPublicKey *pubkey)
151{
152 xmlSecNssPKIKeyDataCtxPtr ctx;
153 KeyType pubType = nullKey ;
154 KeyType priType = nullKey ;
155
156 xmlSecAssert2(xmlSecKeyDataIsValid(data), -1)if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",156,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
(-1); }
;
157 xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",157,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return(-1); }
;
158
159 if( privkey != NULL((void*)0) ) {
160 priType = SECKEY_GetPrivateKeyType( privkey ) ;
161 }
162
163 if( pubkey != NULL((void*)0) ) {
164 pubType = SECKEY_GetPublicKeyType( pubkey ) ;
165 }
166
167 if( priType != nullKey && pubType != nullKey ) {
168 if( pubType != priType ) {
169 xmlSecError( XMLSEC_ERRORS_HERE"pkikeys.c",169,__FUNCTION__ ,
170 NULL((void*)0) ,
171 NULL((void*)0) ,
172 XMLSEC_ERRORS_R_CRYPTO_FAILED4 ,
173 "different type of private and public key" ) ;
174 return -1 ;
175 }
176 }
177
178 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
179 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",179,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
180
181 if (ctx->privkey) {
182 SECKEY_DestroyPrivateKey(ctx->privkey);
183 }
184 ctx->privkey = privkey;
185
186 if (ctx->pubkey) {
187 SECKEY_DestroyPublicKey(ctx->pubkey);
188 }
189 ctx->pubkey = pubkey;
190
191 return(0);
192}
193
194/**
195 * xmlSecNssPKIAdoptKey:
196 * @privkey: the NSS Private Key handle
197 * @pubkey: the NSS Public Key handle
198 *
199 * Build a KeyData object from the given Private Key and Public
200 * Key handles.
201 *
202 * Returns: pointer to KeyData object or NULL if an error occurs.
203 */
204xmlSecKeyDataPtr
205xmlSecNssPKIAdoptKey(SECKEYPrivateKey *privkey,
206 SECKEYPublicKey *pubkey)
207{
208 xmlSecKeyDataPtr data = NULL((void*)0);
209 int ret;
210 KeyType pubType = nullKey ;
211 KeyType priType = nullKey ;
212
213 if( privkey != NULL((void*)0) ) {
214 priType = SECKEY_GetPrivateKeyType( privkey ) ;
215 }
216
217 if( pubkey != NULL((void*)0) ) {
218 pubType = SECKEY_GetPublicKeyType( pubkey ) ;
219 }
220
221 if( priType != nullKey && pubType != nullKey ) {
222 if( pubType != priType ) {
223 xmlSecError( XMLSEC_ERRORS_HERE"pkikeys.c",223,__FUNCTION__ ,
224 NULL((void*)0) ,
225 NULL((void*)0) ,
226 XMLSEC_ERRORS_R_CRYPTO_FAILED4 ,
227 "different type of private and public key" ) ;
228 return( NULL((void*)0) ) ;
229 }
230 }
231
232 pubType = priType != nullKey ? priType : pubType ;
233 switch(pubType) {
234#ifndef XMLSEC_NO_RSA
235 case rsaKey:
236 data = xmlSecKeyDataCreate(xmlSecNssKeyDataRsaIdxmlSecNssKeyDataRsaGetKlass());
237 if(data == NULL((void*)0)) {
238 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",238,__FUNCTION__,
239 NULL((void*)0),
240 "xmlSecKeyDataCreate",
241 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
242 "xmlSecNssKeyDataRsaId");
243 return(NULL((void*)0));
244 }
245 break;
246#endif /* XMLSEC_NO_RSA */
247#ifndef XMLSEC_NO_DSA
248 case dsaKey:
249 data = xmlSecKeyDataCreate(xmlSecNssKeyDataDsaIdxmlSecNssKeyDataDsaGetKlass());
250 if(data == NULL((void*)0)) {
251 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",251,__FUNCTION__,
252 NULL((void*)0),
253 "xmlSecKeyDataCreate",
254 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
255 "xmlSecNssKeyDataDsaId");
256 return(NULL((void*)0));
257 }
258 break;
259#endif /* XMLSEC_NO_DSA */
260 default:
261 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",261,__FUNCTION__,
262 NULL((void*)0),
263 NULL((void*)0),
264 XMLSEC_ERRORS_R_INVALID_TYPE14,
265 "PKI key type %d not supported", pubType);
266 return(NULL((void*)0));
267 }
268
269 xmlSecAssert2(data != NULL, NULL)if(!( data != ((void*)0) ) ) { xmlSecError("pkikeys.c",269,__FUNCTION__
, ((void*)0), "data != NULL", 100, " "); return(((void*)0)); }
;
270 ret = xmlSecNssPKIKeyDataAdoptKey(data, privkey, pubkey);
271 if(ret < 0) {
272 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",272,__FUNCTION__,
273 NULL((void*)0),
274 "xmlSecNssPKIKeyDataAdoptKey",
275 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
276 XMLSEC_ERRORS_NO_MESSAGE" ");
277 xmlSecKeyDataDestroy(data);
278 return(NULL((void*)0));
279 }
280 return(data);
281}
282
283/**
284 * xmlSecNssPKIKeyDataGetPubKey:
285 * @data: the pointer to NSS Key data.
286 *
287 * Gets the Public Key from the key data.
288 *
289 * Returns: pointer to SECKEYPublicKey or NULL if an error occurs.
290 * Caller is responsible for freeing the key when done
291 */
292SECKEYPublicKey *
293xmlSecNssPKIKeyDataGetPubKey(xmlSecKeyDataPtr data) {
294 xmlSecNssPKIKeyDataCtxPtr ctx;
295 SECKEYPublicKey *ret;
296
297 xmlSecAssert2(xmlSecKeyDataIsValid(data), NULL)if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",297,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
(((void*)0)); }
;
298 xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize), NULL)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",298,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return(((void*)0)); }
;
299
300 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
301 xmlSecAssert2(ctx != NULL, NULL)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",301,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(((void*)0)); }
;
302 xmlSecAssert2(ctx->pubkey != NULL, NULL)if(!( ctx->pubkey != ((void*)0) ) ) { xmlSecError("pkikeys.c"
,302,__FUNCTION__, ((void*)0), "ctx->pubkey != NULL", 100,
" "); return(((void*)0)); }
;
303
304 ret = SECKEY_CopyPublicKey(ctx->pubkey);
305 return(ret);
306}
307
308/**
309 * xmlSecNssPKIKeyDataGetPrivKey:
310 * @data: the pointer to NSS Key data.
311 *
312 * Gets the Private Key from the key data.
313 *
314 * Returns: pointer to SECKEYPrivateKey or NULL if an error occurs.
315 * Caller is responsible for freeing the key when done
316 */
317SECKEYPrivateKey*
318xmlSecNssPKIKeyDataGetPrivKey(xmlSecKeyDataPtr data) {
319 xmlSecNssPKIKeyDataCtxPtr ctx;
320 SECKEYPrivateKey* ret;
321
322 xmlSecAssert2(xmlSecKeyDataIsValid(data), NULL)if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",322,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
(((void*)0)); }
;
323 xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize), NULL)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",323,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return(((void*)0)); }
;
324
325 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
326 xmlSecAssert2(ctx != NULL, NULL)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",326,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(((void*)0)); }
;
327 xmlSecAssert2(ctx->privkey != NULL, NULL)if(!( ctx->privkey != ((void*)0) ) ) { xmlSecError("pkikeys.c"
,327,__FUNCTION__, ((void*)0), "ctx->privkey != NULL", 100
, " "); return(((void*)0)); }
;
328
329 ret = SECKEY_CopyPrivateKey(ctx->privkey);
330 return(ret);
331}
332
333/**
334 * xmlSecNssPKIKeyDataGetKeyType:
335 * @data: the pointer to NSS Key data.
336 *
337 * Gets the Key Type from the key data.
338 *
339 * Returns: Key Type
340 */
341KeyType
342xmlSecNssPKIKeyDataGetKeyType(xmlSecKeyDataPtr data) {
343 xmlSecNssPKIKeyDataCtxPtr ctx;
344 KeyType kt;
345
346 xmlSecAssert2(xmlSecKeyDataIsValid(data), nullKey)if(!( ((( data ) != ((void*)0)) && (( data )->id !=
((void*)0)) && (( data )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( data )->id->objSize
>= sizeof(xmlSecKeyData)) && (( data )->id->
name != ((void*)0))) ) ) { xmlSecError("pkikeys.c",346,__FUNCTION__
, ((void*)0), "xmlSecKeyDataIsValid(data)", 100, " "); return
(nullKey); }
;
347 xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize), nullKey)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && (( data )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",347,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(data, xmlSecNssPKIKeyDataSize)", 100
, " "); return(nullKey); }
;
348
349 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
350 xmlSecAssert2(ctx != NULL, nullKey)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",350,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(nullKey); }
;
351
352 if (ctx->pubkey != NULL((void*)0)) {
353 kt = SECKEY_GetPublicKeyType(ctx->pubkey);
354 } else {
355 kt = SECKEY_GetPrivateKeyType(ctx->privkey);
356 }
357 return(kt);
358}
359
360/**
361 * xmlSecNssPKIKeyDataDuplicate
362 * @dst: the pointer to NSS Key data to copy to.
363 * @src: the pointer to NSS Key data to copy from.
364 *
365 * Duplicates the keydata from src to dst
366 *
367 * Returns: -1 on error, 0 on success
368 */
369int
370xmlSecNssPKIKeyDataDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
371 xmlSecNssPKIKeyDataCtxPtr ctxDst;
372 xmlSecNssPKIKeyDataCtxPtr ctxSrc;
373
374 xmlSecAssert2(xmlSecKeyDataIsValid(dst), -1)if(!( ((( dst ) != ((void*)0)) && (( dst )->id != (
(void*)0)) && (( dst )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( dst )->id->objSize >=
sizeof(xmlSecKeyData)) && (( dst )->id->name !=
((void*)0))) ) ) { xmlSecError("pkikeys.c",374,__FUNCTION__,
((void*)0), "xmlSecKeyDataIsValid(dst)", 100, " "); return(-
1); }
;
375 xmlSecAssert2(xmlSecKeyDataCheckSize(dst, xmlSecNssPKIKeyDataSize), -1)if(!( (((( ( dst ) ) != ((void*)0)) && (( ( dst ) )->
id != ((void*)0)) && (( ( dst ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( dst ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( dst
) )->id->name != ((void*)0))) && (( dst )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",375,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(dst, xmlSecNssPKIKeyDataSize)", 100
, " "); return(-1); }
;
376 xmlSecAssert2(xmlSecKeyDataIsValid(src), -1)if(!( ((( src ) != ((void*)0)) && (( src )->id != (
(void*)0)) && (( src )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( src )->id->objSize >=
sizeof(xmlSecKeyData)) && (( src )->id->name !=
((void*)0))) ) ) { xmlSecError("pkikeys.c",376,__FUNCTION__,
((void*)0), "xmlSecKeyDataIsValid(src)", 100, " "); return(-
1); }
;
377 xmlSecAssert2(xmlSecKeyDataCheckSize(src, xmlSecNssPKIKeyDataSize), -1)if(!( (((( ( src ) ) != ((void*)0)) && (( ( src ) )->
id != ((void*)0)) && (( ( src ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( src ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( src
) )->id->name != ((void*)0))) && (( src )->
id->objSize >= (sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx
)))) ) ) { xmlSecError("pkikeys.c",377,__FUNCTION__, ((void*)
0), "xmlSecKeyDataCheckSize(src, xmlSecNssPKIKeyDataSize)", 100
, " "); return(-1); }
;
378
379 ctxDst = xmlSecNssPKIKeyDataGetCtx(dst)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(dst)) + sizeof
(xmlSecKeyData)))
;
380 xmlSecAssert2(ctxDst != NULL, -1)if(!( ctxDst != ((void*)0) ) ) { xmlSecError("pkikeys.c",380,
__FUNCTION__, ((void*)0), "ctxDst != NULL", 100, " "); return
(-1); }
;
381
382 ctxSrc = xmlSecNssPKIKeyDataGetCtx(src)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(src)) + sizeof
(xmlSecKeyData)))
;
383 xmlSecAssert2(ctxSrc != NULL, -1)if(!( ctxSrc != ((void*)0) ) ) { xmlSecError("pkikeys.c",383,
__FUNCTION__, ((void*)0), "ctxSrc != NULL", 100, " "); return
(-1); }
;
384
385 if (xmlSecNSSPKIKeyDataCtxDup(ctxDst, ctxSrc) != 0) {
386 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",386,__FUNCTION__,
387 xmlSecErrorsSafeString(xmlSecKeyDataGetName(dst))(((((((( (dst) ) != ((void*)0)) && (( (dst) )->id !=
((void*)0)) && (( (dst) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (dst) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (dst) )->
id->name != ((void*)0)))) ? ((((dst)->id)) ? (((dst)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (dst) ) != ((void*)0)) && (( (dst) )->
id != ((void*)0)) && (( (dst) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (dst) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (dst) )->
id->name != ((void*)0)))) ? ((((dst)->id)) ? (((dst)->
id)->name) : ((void*)0)) : ((void*)0)))) : (char*)"NULL")
,
388 "xmlSecNssPKIKeydataCtxDup",
389 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
390 XMLSEC_ERRORS_NO_MESSAGE" ");
391 return(-1);
392 }
393
394 return(0);
395}
396
397#ifndef XMLSEC_NO_DSA
398/**************************************************************************
399 *
400 * <dsig:DSAKeyValue> processing
401 *
402 *
403 * The DSAKeyValue Element (http://www.w3.org/TR/xmldsig-core/#sec-DSAKeyValue)
404 *
405 * DSA keys and the DSA signature algorithm are specified in [DSS].
406 * DSA public key values can have the following fields:
407 *
408 * * P - a prime modulus meeting the [DSS] requirements
409 * * Q - an integer in the range 2**159 < Q < 2**160 which is a prime
410 * divisor of P-1
411 * * G - an integer with certain properties with respect to P and Q
412 * * Y - G**X mod P (where X is part of the private key and not made
413 * public)
414 * * J - (P - 1) / Q
415 * * seed - a DSA prime generation seed
416 * * pgenCounter - a DSA prime generation counter
417 *
418 * Parameter J is available for inclusion solely for efficiency as it is
419 * calculatable from P and Q. Parameters seed and pgenCounter are used in the
420 * DSA prime number generation algorithm specified in [DSS]. As such, they are
421 * optional but must either both be present or both be absent. This prime
422 * generation algorithm is designed to provide assurance that a weak prime is
423 * not being used and it yields a P and Q value. Parameters P, Q, and G can be
424 * public and common to a group of users. They might be known from application
425 * context. As such, they are optional but P and Q must either both appear or
426 * both be absent. If all of P, Q, seed, and pgenCounter are present,
427 * implementations are not required to check if they are consistent and are
428 * free to use either P and Q or seed and pgenCounter. All parameters are
429 * encoded as base64 [MIME] values.
430 *
431 * Arbitrary-length integers (e.g. "bignums" such as RSA moduli) are
432 * represented in XML as octet strings as defined by the ds:CryptoBinary type.
433 *
434 * Schema Definition:
435 *
436 * <element name="DSAKeyValue" type="ds:DSAKeyValueType"/>
437 * <complexType name="DSAKeyValueType">
438 * <sequence>
439 * <sequence minOccurs="0">
440 * <element name="P" type="ds:CryptoBinary"/>
441 * <element name="Q" type="ds:CryptoBinary"/>
442 * </sequence>
443 * <element name="G" type="ds:CryptoBinary" minOccurs="0"/>
444 * <element name="Y" type="ds:CryptoBinary"/>
445 * <element name="J" type="ds:CryptoBinary" minOccurs="0"/>
446 * <sequence minOccurs="0">
447 * <element name="Seed" type="ds:CryptoBinary"/>
448 * <element name="PgenCounter" type="ds:CryptoBinary"/>
449 * </sequence>
450 * </sequence>
451 * </complexType>
452 *
453 * DTD Definition:
454 *
455 * <!ELEMENT DSAKeyValue ((P, Q)?, G?, Y, J?, (Seed, PgenCounter)?) >
456 * <!ELEMENT P (#PCDATA) >
457 * <!ELEMENT Q (#PCDATA) >
458 * <!ELEMENT G (#PCDATA) >
459 * <!ELEMENT Y (#PCDATA) >
460 * <!ELEMENT J (#PCDATA) >
461 * <!ELEMENT Seed (#PCDATA) >
462 * <!ELEMENT PgenCounter (#PCDATA) >
463 *
464 * ============================================================================
465 *
466 * To support reading/writing private keys an X element added (before Y).
467 * todo: The current implementation does not support Seed and PgenCounter!
468 * by this the P, Q and G are *required*!
469 *
470 *************************************************************************/
471static int xmlSecNssKeyDataDsaInitialize (xmlSecKeyDataPtr data);
472static int xmlSecNssKeyDataDsaDuplicate (xmlSecKeyDataPtr dst,
473 xmlSecKeyDataPtr src);
474static void xmlSecNssKeyDataDsaFinalize (xmlSecKeyDataPtr data);
475static int xmlSecNssKeyDataDsaXmlRead (xmlSecKeyDataId id,
476 xmlSecKeyPtr key,
477 xmlNodePtr node,
478 xmlSecKeyInfoCtxPtr keyInfoCtx);
479static int xmlSecNssKeyDataDsaXmlWrite (xmlSecKeyDataId id,
480 xmlSecKeyPtr key,
481 xmlNodePtr node,
482 xmlSecKeyInfoCtxPtr keyInfoCtx);
483static int xmlSecNssKeyDataDsaGenerate (xmlSecKeyDataPtr data,
484 xmlSecSizesize_t sizeBits,
485 xmlSecKeyDataType type);
486
487static xmlSecKeyDataType xmlSecNssKeyDataDsaGetType (xmlSecKeyDataPtr data);
488static xmlSecSizesize_t xmlSecNssKeyDataDsaGetSize (xmlSecKeyDataPtr data);
489static void xmlSecNssKeyDataDsaDebugDump (xmlSecKeyDataPtr data,
490 FILE* output);
491static void xmlSecNssKeyDataDsaDebugXmlDump (xmlSecKeyDataPtr data,
492 FILE* output);
493
494static xmlSecKeyDataKlass xmlSecNssKeyDataDsaKlass = {
495 sizeof(xmlSecKeyDataKlass),
496 xmlSecNssPKIKeyDataSize(sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx)),
497
498 /* data */
499 xmlSecNameDSAKeyValue,
500 xmlSecKeyDataUsageKeyValueNode(0x00004 | 0x00008) | xmlSecKeyDataUsageRetrievalMethodNodeXml0x00010,
501 /* xmlSecKeyDataUsage usage; */
502 xmlSecHrefDSAKeyValue, /* const xmlChar* href; */
503 xmlSecNodeDSAKeyValue, /* const xmlChar* dataNodeName; */
504 xmlSecDSigNs, /* const xmlChar* dataNodeNs; */
505
506 /* constructors/destructor */
507 xmlSecNssKeyDataDsaInitialize, /* xmlSecKeyDataInitializeMethod initialize; */
508 xmlSecNssKeyDataDsaDuplicate, /* xmlSecKeyDataDuplicateMethod duplicate; */
509 xmlSecNssKeyDataDsaFinalize, /* xmlSecKeyDataFinalizeMethod finalize; */
510 xmlSecNssKeyDataDsaGenerate, /* xmlSecKeyDataGenerateMethod generate; */
511
512 /* get info */
513 xmlSecNssKeyDataDsaGetType, /* xmlSecKeyDataGetTypeMethod getType; */
514 xmlSecNssKeyDataDsaGetSize, /* xmlSecKeyDataGetSizeMethod getSize; */
515 NULL((void*)0), /* xmlSecKeyDataGetIdentifier getIdentifier; */
516
517 /* read/write */
518 xmlSecNssKeyDataDsaXmlRead, /* xmlSecKeyDataXmlReadMethod xmlRead; */
519 xmlSecNssKeyDataDsaXmlWrite, /* xmlSecKeyDataXmlWriteMethod xmlWrite; */
520 NULL((void*)0), /* xmlSecKeyDataBinReadMethod binRead; */
521 NULL((void*)0), /* xmlSecKeyDataBinWriteMethod binWrite; */
522
523 /* debug */
524 xmlSecNssKeyDataDsaDebugDump, /* xmlSecKeyDataDebugDumpMethod debugDump; */
525 xmlSecNssKeyDataDsaDebugXmlDump, /* xmlSecKeyDataDebugDumpMethod debugXmlDump; */
526
527 /* reserved for the future */
528 NULL((void*)0), /* void* reserved0; */
529 NULL((void*)0), /* void* reserved1; */
530};
531
532/**
533 * xmlSecNssKeyDataDsaGetKlass:
534 *
535 * The DSA key data klass.
536 *
537 * Returns: pointer to DSA key data klass.
538 */
539xmlSecKeyDataId
540xmlSecNssKeyDataDsaGetKlass(void) {
541 return(&xmlSecNssKeyDataDsaKlass);
542}
543
544
545static int
546xmlSecNssKeyDataDsaInitialize(xmlSecKeyDataPtr data) {
547 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",547,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return(-1); }
;
548
549 return(xmlSecNssPKIKeyDataInitialize(data));
550}
551
552static int
553xmlSecNssKeyDataDsaDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
554 xmlSecAssert2(xmlSecKeyDataCheckId(dst, xmlSecNssKeyDataDsaId), -1)if(!( (((( ( dst ) ) != ((void*)0)) && (( ( dst ) )->
id != ((void*)0)) && (( ( dst ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( dst ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( dst
) )->id->name != ((void*)0))) && ((( dst )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",554,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(dst, xmlSecNssKeyDataDsaId)"
, 100, " "); return(-1); }
;
555 xmlSecAssert2(xmlSecKeyDataCheckId(src, xmlSecNssKeyDataDsaId), -1)if(!( (((( ( src ) ) != ((void*)0)) && (( ( src ) )->
id != ((void*)0)) && (( ( src ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( src ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( src
) )->id->name != ((void*)0))) && ((( src )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",555,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(src, xmlSecNssKeyDataDsaId)"
, 100, " "); return(-1); }
;
556
557 return(xmlSecNssPKIKeyDataDuplicate(dst, src));
558}
559
560static void
561xmlSecNssKeyDataDsaFinalize(xmlSecKeyDataPtr data) {
562 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",562,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return; }
;
563
564 xmlSecNssPKIKeyDataFinalize(data);
565}
566
567static int
568xmlSecNssKeyDataDsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
569 xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
570 xmlSecKeyDataPtr data = NULL((void*)0);
571 xmlNodePtr cur;
572 int ret;
573 PK11SlotInfo *slot = NULL((void*)0);
574 CK_OBJECT_HANDLE handle;
575 SECKEYPublicKey *pubkey=NULL((void*)0);
576 PRArenaPoolPLArenaPool *arena = NULL((void*)0);
577
578
579 xmlSecAssert2(id == xmlSecNssKeyDataDsaId, -1)if(!( id == xmlSecNssKeyDataDsaGetKlass() ) ) { xmlSecError("pkikeys.c"
,579,__FUNCTION__, ((void*)0), "id == xmlSecNssKeyDataDsaId",
100, " "); return(-1); }
;
580 xmlSecAssert2(key != NULL, -1)if(!( key != ((void*)0) ) ) { xmlSecError("pkikeys.c",580,__FUNCTION__
, ((void*)0), "key != NULL", 100, " "); return(-1); }
;
581 xmlSecAssert2(node != NULL, -1)if(!( node != ((void*)0) ) ) { xmlSecError("pkikeys.c",581,__FUNCTION__
, ((void*)0), "node != NULL", 100, " "); return(-1); }
;
582 xmlSecAssert2(keyInfoCtx != NULL, -1)if(!( keyInfoCtx != ((void*)0) ) ) { xmlSecError("pkikeys.c",
582,__FUNCTION__, ((void*)0), "keyInfoCtx != NULL", 100, " ")
; return(-1); }
;
583
584 if(xmlSecKeyGetValue(key) != NULL((void*)0)) {
585 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",585,__FUNCTION__,
586 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
587 NULL((void*)0),
588 XMLSEC_ERRORS_R_INVALID_KEY_DATA41,
589 XMLSEC_ERRORS_NO_MESSAGE" ");
590 ret = -1;
591 goto done;
592 }
593
594 slot = xmlSecNssSlotGet(CKM_DSA0x00000011);
595 if(slot == NULL((void*)0)) {
596 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",596,__FUNCTION__,
597 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
598 "xmlSecNssSlotGet",
599 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
600 "error code=%d", PORT_GetError());
601 ret = -1;
602 goto done;
603 }
604
605 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE(2048));
606 if(arena == NULL((void*)0)) {
607 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",607,__FUNCTION__,
608 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
609 "PORT_NewArena",
610 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
611 "error code=%d", PORT_GetError());
612 ret = -1;
613 goto done;
614 }
615
616 pubkey = (SECKEYPublicKey *)PORT_ArenaZAlloc(arena,
617 sizeof(SECKEYPublicKey));
618 if(pubkey == NULL((void*)0) ) {
619 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",619,__FUNCTION__,
620 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
621 "PORT_ArenaZAlloc",
622 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
623 "error code=%d", PORT_GetError());
624 PORT_FreeArena(arena, PR_FALSE0);
625 ret = -1;
626 goto done;
627 }
628 pubkey->arena = arena;
629 pubkey->u.dsa.params.arena = arena;
630 pubkey->keyType = dsaKey;
631
632 cur = xmlSecGetNextElementNode(node->children);
633
634 /* first is P node. It is REQUIRED because we do not support Seed and PgenCounter*/
635 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAP, xmlSecDSigNs))) {
636 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",636,__FUNCTION__,
637 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
638 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
639 XMLSEC_ERRORS_R_INVALID_NODE21,
640 "node=%s",
641 xmlSecErrorsSafeString(xmlSecNodeDSAP)(((xmlSecNodeDSAP) != ((void*)0)) ? ((char*)(xmlSecNodeDSAP))
: (char*)"NULL")
);
642 ret = -1;
643 goto done;
644 }
645 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.dsa.params.prime)) == NULL((void*)0)) {
646 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",646,__FUNCTION__,
647 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
648 "xmlSecNssNodeGetBigNumValue",
649 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
650 "node=%s",
651 xmlSecErrorsSafeString(xmlSecNodeDSAP)(((xmlSecNodeDSAP) != ((void*)0)) ? ((char*)(xmlSecNodeDSAP))
: (char*)"NULL")
);
652 ret = -1;
653 goto done;
654 }
655 cur = xmlSecGetNextElementNode(cur->next);
656
657 /* next is Q node. It is REQUIRED because we do not support Seed and PgenCounter*/
658 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAQ, xmlSecDSigNs))) {
659 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",659,__FUNCTION__,
660 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
661 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
662 XMLSEC_ERRORS_R_INVALID_NODE21,
663 "node=%s",
664 xmlSecErrorsSafeString(xmlSecNodeDSAQ)(((xmlSecNodeDSAQ) != ((void*)0)) ? ((char*)(xmlSecNodeDSAQ))
: (char*)"NULL")
);
665 ret = -1;
666 goto done;
667 }
668 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.dsa.params.subPrime)) == NULL((void*)0)) {
669 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",669,__FUNCTION__,
670 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
671 "xmlSecNssNodeGetBigNumValue",
672 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
673 "node=%s",
674 xmlSecErrorsSafeString(xmlSecNodeDSAQ)(((xmlSecNodeDSAQ) != ((void*)0)) ? ((char*)(xmlSecNodeDSAQ))
: (char*)"NULL")
);
675 ret = -1;
676 goto done;
677 }
678 cur = xmlSecGetNextElementNode(cur->next);
679
680 /* next is G node. It is REQUIRED because we do not support Seed and PgenCounter*/
681 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAG, xmlSecDSigNs))) {
682 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",682,__FUNCTION__,
683 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
684 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
685 XMLSEC_ERRORS_R_INVALID_NODE21,
686 "node=%s",
687 xmlSecErrorsSafeString(xmlSecNodeDSAG)(((xmlSecNodeDSAG) != ((void*)0)) ? ((char*)(xmlSecNodeDSAG))
: (char*)"NULL")
);
688 ret = -1;
689 goto done;
690 }
691 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.dsa.params.base)) == NULL((void*)0)) {
692 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",692,__FUNCTION__,
693 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
694 "xmlSecNssNodeGetBigNumValue",
695 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
696 "node=%s",
697 xmlSecErrorsSafeString(xmlSecNodeDSAG)(((xmlSecNodeDSAG) != ((void*)0)) ? ((char*)(xmlSecNodeDSAG))
: (char*)"NULL")
);
698 ret = -1;
699 goto done;
700 }
701 cur = xmlSecGetNextElementNode(cur->next);
702
703 if((cur != NULL((void*)0)) && (xmlSecCheckNodeName(cur, xmlSecNodeDSAX, xmlSecNs))) {
704 /* next is X node. It is REQUIRED for private key but
705 * NSS does not support it, we just ignore it */
706
707 cur = xmlSecGetNextElementNode(cur->next);
708 }
709
710 /* next is Y node. */
711 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeDSAY, xmlSecDSigNs))) {
712 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",712,__FUNCTION__,
713 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
714 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
715 XMLSEC_ERRORS_R_INVALID_NODE21,
716 "node=%s",
717 xmlSecErrorsSafeString(xmlSecNodeDSAY)(((xmlSecNodeDSAY) != ((void*)0)) ? ((char*)(xmlSecNodeDSAY))
: (char*)"NULL")
);
718 ret = -1;
719 goto done;
720 }
721 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.dsa.publicValue)) == NULL((void*)0)) {
722 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",722,__FUNCTION__,
723 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
724 "xmlSecNssNodeGetBigNumValue",
725 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
726 "node=%s", xmlSecErrorsSafeString(xmlSecNodeDSAY)(((xmlSecNodeDSAY) != ((void*)0)) ? ((char*)(xmlSecNodeDSAY))
: (char*)"NULL")
);
727 ret = -1;
728 goto done;
729 }
730 cur = xmlSecGetNextElementNode(cur->next);
731
732 /* todo: add support for J */
733 if((cur != NULL((void*)0)) && (xmlSecCheckNodeName(cur, xmlSecNodeDSAJ, xmlSecDSigNs))) {
734 cur = xmlSecGetNextElementNode(cur->next);
735 }
736
737 /* todo: add support for seed */
738 if((cur != NULL((void*)0)) && (xmlSecCheckNodeName(cur, xmlSecNodeDSASeed, xmlSecDSigNs))) {
739 cur = xmlSecGetNextElementNode(cur->next);
740 }
741
742 /* todo: add support for pgencounter */
743 if((cur != NULL((void*)0)) && (xmlSecCheckNodeName(cur, xmlSecNodeDSAPgenCounter, xmlSecDSigNs))) {
744 cur = xmlSecGetNextElementNode(cur->next);
745 }
746
747 if(cur != NULL((void*)0)) {
748 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",748,__FUNCTION__,
749 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
750 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
751 XMLSEC_ERRORS_R_UNEXPECTED_NODE27,
752 XMLSEC_ERRORS_NO_MESSAGE" ");
753 ret = -1;
754 goto done;
755 }
756
757 handle = PK11_ImportPublicKey(slot, pubkey, PR_FALSE0);
Value stored to 'handle' is never read
758
759 data = xmlSecKeyDataCreate(id);
760 if(data == NULL((void*)0) ) {
761 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",761,__FUNCTION__,
762 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
763 "xmlSecKeyDataCreate",
764 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
765 XMLSEC_ERRORS_NO_MESSAGE" ");
766 ret = -1;
767 goto done;
768 }
769
770 ret = xmlSecNssPKIKeyDataAdoptKey(data, NULL((void*)0), pubkey);
771 if(ret < 0) {
772 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",772,__FUNCTION__,
773 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
774 "xmlSecNssPKIKeyDataAdoptKey",
775 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
776 XMLSEC_ERRORS_NO_MESSAGE" ");
777 goto done;
778 }
779 pubkey = NULL((void*)0);
780
781 ret = xmlSecKeySetValue(key, data);
782 if(ret < 0) {
783 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",783,__FUNCTION__,
784 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
785 "xmlSecKeySetValue",
786 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
787 XMLSEC_ERRORS_NO_MESSAGE" ");
788 goto done;
789 }
790 data = NULL((void*)0);
791
792 ret = 0;
793
794done:
795 if (slot != NULL((void*)0)) {
796 PK11_FreeSlot(slot);
797 }
798
799 if (pubkey != NULL((void*)0)) {
800 SECKEY_DestroyPublicKey(pubkey);
801 }
802 if (data != NULL((void*)0)) {
803 xmlSecKeyDataDestroy(data);
804 }
805
806 return(ret);
807}
808
809static int
810xmlSecNssKeyDataDsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
811 xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
812 xmlSecNssPKIKeyDataCtxPtr ctx;
813 xmlNodePtr cur;
814 int ret;
815
816 xmlSecAssert2(id == xmlSecNssKeyDataDsaId, -1)if(!( id == xmlSecNssKeyDataDsaGetKlass() ) ) { xmlSecError("pkikeys.c"
,816,__FUNCTION__, ((void*)0), "id == xmlSecNssKeyDataDsaId",
100, " "); return(-1); }
;
817 xmlSecAssert2(key != NULL, -1)if(!( key != ((void*)0) ) ) { xmlSecError("pkikeys.c",817,__FUNCTION__
, ((void*)0), "key != NULL", 100, " "); return(-1); }
;
818 xmlSecAssert2(xmlSecKeyDataCheckId(xmlSecKeyGetValue(key), xmlSecNssKeyDataDsaId), -1)if(!( (((( ( xmlSecKeyGetValue(key) ) ) != ((void*)0)) &&
(( ( xmlSecKeyGetValue(key) ) )->id != ((void*)0)) &&
(( ( xmlSecKeyGetValue(key) ) )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( ( xmlSecKeyGetValue(key) )
)->id->objSize >= sizeof(xmlSecKeyData)) &&
(( ( xmlSecKeyGetValue(key) ) )->id->name != ((void*)0
))) && ((( xmlSecKeyGetValue(key) )->id) == ( xmlSecNssKeyDataDsaGetKlass
() ))) ) ) { xmlSecError("pkikeys.c",818,__FUNCTION__, ((void
*)0), "xmlSecKeyDataCheckId(xmlSecKeyGetValue(key), xmlSecNssKeyDataDsaId)"
, 100, " "); return(-1); }
;
819 xmlSecAssert2(node != NULL, -1)if(!( node != ((void*)0) ) ) { xmlSecError("pkikeys.c",819,__FUNCTION__
, ((void*)0), "node != NULL", 100, " "); return(-1); }
;
820 xmlSecAssert2(keyInfoCtx != NULL, -1)if(!( keyInfoCtx != ((void*)0) ) ) { xmlSecError("pkikeys.c",
820,__FUNCTION__, ((void*)0), "keyInfoCtx != NULL", 100, " ")
; return(-1); }
;
821
822 ctx = xmlSecNssPKIKeyDataGetCtx(xmlSecKeyGetValue(key))((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(xmlSecKeyGetValue
(key))) + sizeof(xmlSecKeyData)))
;
823 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",823,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
824/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/
825
826 if(((xmlSecKeyDataTypePublic0x0001 | xmlSecKeyDataTypePrivate0x0002) & keyInfoCtx->keyReq.keyType) == 0) {
827 /* we can have only private key or public key */
828 return(0);
829 }
830
831 /* first is P node */
832 cur = xmlSecAddChild(node, xmlSecNodeDSAP, xmlSecDSigNs);
833 if(cur == NULL((void*)0)) {
834 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",834,__FUNCTION__,
835 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
836 "xmlSecAddChild",
837 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
838 "node=%s",
839 xmlSecErrorsSafeString(xmlSecNodeDSAP)(((xmlSecNodeDSAP) != ((void*)0)) ? ((char*)(xmlSecNodeDSAP))
: (char*)"NULL")
);
840 return(-1);
841 }
842 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.dsa.params.prime), 1);
843 if(ret < 0) {
844 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",844,__FUNCTION__,
845 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
846 "xmlSecNssNodeSetBigNumValue",
847 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
848 "node=%s",
849 xmlSecErrorsSafeString(xmlSecNodeDSAP)(((xmlSecNodeDSAP) != ((void*)0)) ? ((char*)(xmlSecNodeDSAP))
: (char*)"NULL")
);
850 return(-1);
851 }
852
853 /* next is Q node. */
854 cur = xmlSecAddChild(node, xmlSecNodeDSAQ, xmlSecDSigNs);
855 if(cur == NULL((void*)0)) {
856 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",856,__FUNCTION__,
857 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
858 "xmlSecAddChild",
859 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
860 "node=%s",
861 xmlSecErrorsSafeString(xmlSecNodeDSAQ)(((xmlSecNodeDSAQ) != ((void*)0)) ? ((char*)(xmlSecNodeDSAQ))
: (char*)"NULL")
);
862 return(-1);
863 }
864 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.dsa.params.subPrime), 1);
865 if(ret < 0) {
866 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",866,__FUNCTION__,
867 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
868 "xmlSecNssNodeSetBigNumValue",
869 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
870 "node=%s",
871 xmlSecErrorsSafeString(xmlSecNodeDSAQ)(((xmlSecNodeDSAQ) != ((void*)0)) ? ((char*)(xmlSecNodeDSAQ))
: (char*)"NULL")
);
872 return(-1);
873 }
874
875 /* next is G node. */
876 cur = xmlSecAddChild(node, xmlSecNodeDSAG, xmlSecDSigNs);
877 if(cur == NULL((void*)0)) {
878 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",878,__FUNCTION__,
879 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
880 "xmlSecAddChild",
881 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
882 "node=%s",
883 xmlSecErrorsSafeString(xmlSecNodeDSAG)(((xmlSecNodeDSAG) != ((void*)0)) ? ((char*)(xmlSecNodeDSAG))
: (char*)"NULL")
);
884 return(-1);
885 }
886 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.dsa.params.base), 1);
887 if(ret < 0) {
888 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",888,__FUNCTION__,
889 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
890 "xmlSecNssNodeSetBigNumValue",
891 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
892 "node=%s",
893 xmlSecErrorsSafeString(xmlSecNodeDSAG)(((xmlSecNodeDSAG) != ((void*)0)) ? ((char*)(xmlSecNodeDSAG))
: (char*)"NULL")
);
894 return(-1);
895 }
896
897 /* next is X node: not supported in NSS */
898
899 /* next is Y node. */
900 cur = xmlSecAddChild(node, xmlSecNodeDSAY, xmlSecDSigNs);
901 if(cur == NULL((void*)0)) {
902 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",902,__FUNCTION__,
903 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
904 "xmlSecAddChild",
905 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
906 "node=%s",
907 xmlSecErrorsSafeString(xmlSecNodeDSAY)(((xmlSecNodeDSAY) != ((void*)0)) ? ((char*)(xmlSecNodeDSAY))
: (char*)"NULL")
);
908 return(-1);
909 }
910 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.dsa.publicValue), 1);
911 if(ret < 0) {
912 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",912,__FUNCTION__,
913 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
914 "xmlSecNssNodeSetBigNumValue",
915 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
916 "node=%s",
917 xmlSecErrorsSafeString(xmlSecNodeDSAY)(((xmlSecNodeDSAY) != ((void*)0)) ? ((char*)(xmlSecNodeDSAY))
: (char*)"NULL")
);
918 return(-1);
919 }
920
921 return(0);
922}
923
924static int
925xmlSecNssKeyDataDsaGenerate(xmlSecKeyDataPtr data, xmlSecSizesize_t sizeBits, xmlSecKeyDataType type ATTRIBUTE_UNUSED__attribute__((unused))) {
926 PQGParams *pqgParams = NULL((void*)0);
927 PQGVerify *pqgVerify = NULL((void*)0);
928 SECStatus rv;
929 SECStatus res;
930 PK11SlotInfo *slot = NULL((void*)0);
931 SECKEYPrivateKey *privkey = NULL((void*)0);
932 SECKEYPublicKey *pubkey = NULL((void*)0);
933 int ret = -1;
934 int j;
935
936 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",936,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return(-1); }
;
937 xmlSecAssert2(sizeBits > 0, -1)if(!( sizeBits > 0 ) ) { xmlSecError("pkikeys.c",937,__FUNCTION__
, ((void*)0), "sizeBits > 0", 100, " "); return(-1); }
;
938
939 j = PQG_PBITS_TO_INDEX(sizeBits)(((sizeBits) < 512 || (sizeBits) > 1024 || (sizeBits) %
64) ? -1 : (int)((sizeBits)-512)/64)
;
940 rv = PK11_PQG_ParamGen(j, &pqgParams, &pqgVerify);
941 if (rv != SECSuccess) {
942 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",942,__FUNCTION__,
943 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
944 "PK11_PQG_ParamGen",
945 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
946 "size=%d, error code=%d", sizeBits, PORT_GetError());
947 ret = -1;
948 goto done;
949 }
950
951 rv = PK11_PQG_VerifyParams(pqgParams, pqgVerify, &res);
952 if (rv != SECSuccess || res != SECSuccess) {
953 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",953,__FUNCTION__,
954 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
955 "PK11_PQG_VerifyParams",
956 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
957 "size=%d, error code=%d", sizeBits, PORT_GetError());
958 ret = -1;
959 goto done;
960 }
961
962 slot = xmlSecNssSlotGet(CKM_DSA_KEY_PAIR_GEN0x00000010);
963 PK11_Authenticate(slot, PR_TRUE1, NULL((void*)0) /* default pwd callback */);
964 privkey = PK11_GenerateKeyPair(slot, CKM_DSA_KEY_PAIR_GEN0x00000010, pqgParams,
965 &pubkey, PR_FALSE0, PR_TRUE1, NULL((void*)0));
966
967 if((privkey == NULL((void*)0)) || (pubkey == NULL((void*)0))) {
968 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",968,__FUNCTION__,
969 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
970 "PK11_GenerateKeyPair",
971 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
972 "error code=%d", PORT_GetError());
973
974 ret = -1;
975 goto done;
976 }
977
978 ret = xmlSecNssPKIKeyDataAdoptKey(data, privkey, pubkey);
979 if(ret < 0) {
980 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",980,__FUNCTION__,
981 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
982 "xmlSecNssPKIKeyDataAdoptKey",
983 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
984 XMLSEC_ERRORS_NO_MESSAGE" ");
985 goto done;
986 }
987
988 privkey = NULL((void*)0) ;
989 pubkey = NULL((void*)0) ;
990 ret = 0;
991
992done:
993 if (slot != NULL((void*)0)) {
994 PK11_FreeSlot(slot);
995 }
996 if (pqgParams != NULL((void*)0)) {
997 PK11_PQG_DestroyParams(pqgParams);
998 }
999 if (pqgVerify != NULL((void*)0)) {
1000 PK11_PQG_DestroyVerify(pqgVerify);
1001 }
1002 if (pubkey != NULL((void*)0)) {
1003 SECKEY_DestroyPublicKey(pubkey);
1004 }
1005 if (privkey != NULL((void*)0)) {
1006 SECKEY_DestroyPrivateKey(privkey);
1007 }
1008 return(ret);
1009}
1010
1011static xmlSecKeyDataType
1012xmlSecNssKeyDataDsaGetType(xmlSecKeyDataPtr data) {
1013 xmlSecNssPKIKeyDataCtxPtr ctx;
1014
1015 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), xmlSecKeyDataTypeUnknown)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1015,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return(0x0000); }
;
1016 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
1017 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",1017,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
1018/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/
1019 if (ctx->privkey != NULL((void*)0)) {
1020 return(xmlSecKeyDataTypePrivate0x0002 | xmlSecKeyDataTypePublic0x0001);
1021 } else if( ctx->pubkey != NULL((void*)0) ) {
1022 return(xmlSecKeyDataTypePublic0x0001);
1023 }
1024
1025 return(xmlSecKeyDataTypeUnknown0x0000);
1026}
1027
1028static xmlSecSizesize_t
1029xmlSecNssKeyDataDsaGetSize(xmlSecKeyDataPtr data) {
1030 xmlSecNssPKIKeyDataCtxPtr ctx;
1031
1032 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId), 0)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1032,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return(0); }
;
1033 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
1034 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",1034,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
1035/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == dsaKey, -1);*/
1036
1037 return(8 * SECKEY_PublicKeyStrength(ctx->pubkey));
1038}
1039
1040static void
1041xmlSecNssKeyDataDsaDebugDump(xmlSecKeyDataPtr data, FILE* output) {
1042 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1042,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return; }
;
1043 xmlSecAssert(output != NULL)if(!( output != ((void*)0) ) ) { xmlSecError("pkikeys.c",1043
,__FUNCTION__, ((void*)0), "output != NULL", 100, " "); return
; }
;
1044
1045 fprintf(output, "=== dsa key: size = %d\n",
1046 xmlSecNssKeyDataDsaGetSize(data));
1047}
1048
1049static void
1050xmlSecNssKeyDataDsaDebugXmlDump(xmlSecKeyDataPtr data, FILE* output) {
1051 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataDsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1051,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataDsaId)"
, 100, " "); return; }
;
1052 xmlSecAssert(output != NULL)if(!( output != ((void*)0) ) ) { xmlSecError("pkikeys.c",1052
,__FUNCTION__, ((void*)0), "output != NULL", 100, " "); return
; }
;
1053
1054 fprintf(output, "<DSAKeyValue size=\"%d\" />\n",
1055 xmlSecNssKeyDataDsaGetSize(data));
1056}
1057
1058#endif /* XMLSEC_NO_DSA */
1059
1060#ifndef XMLSEC_NO_RSA
1061/**************************************************************************
1062 *
1063 * <dsig:RSAKeyValue> processing
1064 *
1065 * http://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue
1066 * The RSAKeyValue Element
1067 *
1068 * RSA key values have two fields: Modulus and Exponent.
1069 *
1070 * <RSAKeyValue>
1071 * <Modulus>xA7SEU+e0yQH5rm9kbCDN9o3aPIo7HbP7tX6WOocLZAtNfyxSZDU16ksL6W
1072 * jubafOqNEpcwR3RdFsT7bCqnXPBe5ELh5u4VEy19MzxkXRgrMvavzyBpVRgBUwUlV
1073 * 5foK5hhmbktQhyNdy/6LpQRhDUDsTvK+g9Ucj47es9AQJ3U=
1074 * </Modulus>
1075 * <Exponent>AQAB</Exponent>
1076 * </RSAKeyValue>
1077 *
1078 * Arbitrary-length integers (e.g. "bignums" such as RSA moduli) are
1079 * represented in XML as octet strings as defined by the ds:CryptoBinary type.
1080 *
1081 * Schema Definition:
1082 *
1083 * <element name="RSAKeyValue" type="ds:RSAKeyValueType"/>
1084 * <complexType name="RSAKeyValueType">
1085 * <sequence>
1086 * <element name="Modulus" type="ds:CryptoBinary"/>
1087 * <element name="Exponent" type="ds:CryptoBinary"/>
1088 * </sequence>
1089 * </complexType>
1090 *
1091 * DTD Definition:
1092 *
1093 * <!ELEMENT RSAKeyValue (Modulus, Exponent) >
1094 * <!ELEMENT Modulus (#PCDATA) >
1095 * <!ELEMENT Exponent (#PCDATA) >
1096 *
1097 * ============================================================================
1098 *
1099 * To support reading/writing private keys an PrivateExponent element is added
1100 * to the end
1101 *
1102 *************************************************************************/
1103
1104static int xmlSecNssKeyDataRsaInitialize (xmlSecKeyDataPtr data);
1105static int xmlSecNssKeyDataRsaDuplicate (xmlSecKeyDataPtr dst,
1106 xmlSecKeyDataPtr src);
1107static void xmlSecNssKeyDataRsaFinalize (xmlSecKeyDataPtr data);
1108static int xmlSecNssKeyDataRsaXmlRead (xmlSecKeyDataId id,
1109 xmlSecKeyPtr key,
1110 xmlNodePtr node,
1111 xmlSecKeyInfoCtxPtr keyInfoCtx);
1112static int xmlSecNssKeyDataRsaXmlWrite (xmlSecKeyDataId id,
1113 xmlSecKeyPtr key,
1114 xmlNodePtr node,
1115 xmlSecKeyInfoCtxPtr keyInfoCtx);
1116static int xmlSecNssKeyDataRsaGenerate (xmlSecKeyDataPtr data,
1117 xmlSecSizesize_t sizeBits,
1118 xmlSecKeyDataType type);
1119
1120static xmlSecKeyDataType xmlSecNssKeyDataRsaGetType (xmlSecKeyDataPtr data);
1121static xmlSecSizesize_t xmlSecNssKeyDataRsaGetSize (xmlSecKeyDataPtr data);
1122static void xmlSecNssKeyDataRsaDebugDump (xmlSecKeyDataPtr data,
1123 FILE* output);
1124static void xmlSecNssKeyDataRsaDebugXmlDump (xmlSecKeyDataPtr data,
1125 FILE* output);
1126
1127static xmlSecKeyDataKlass xmlSecNssKeyDataRsaKlass = {
1128 sizeof(xmlSecKeyDataKlass),
1129 xmlSecNssPKIKeyDataSize(sizeof(xmlSecKeyData) + sizeof(xmlSecNssPKIKeyDataCtx)),
1130
1131 /* data */
1132 xmlSecNameRSAKeyValue,
1133 xmlSecKeyDataUsageKeyValueNode(0x00004 | 0x00008) | xmlSecKeyDataUsageRetrievalMethodNodeXml0x00010,
1134 /* xmlSecKeyDataUsage usage; */
1135 xmlSecHrefRSAKeyValue, /* const xmlChar* href; */
1136 xmlSecNodeRSAKeyValue, /* const xmlChar* dataNodeName; */
1137 xmlSecDSigNs, /* const xmlChar* dataNodeNs; */
1138
1139 /* constructors/destructor */
1140 xmlSecNssKeyDataRsaInitialize, /* xmlSecKeyDataInitializeMethod initialize; */
1141 xmlSecNssKeyDataRsaDuplicate, /* xmlSecKeyDataDuplicateMethod duplicate; */
1142 xmlSecNssKeyDataRsaFinalize, /* xmlSecKeyDataFinalizeMethod finalize; */
1143 xmlSecNssKeyDataRsaGenerate, /* xmlSecKeyDataGenerateMethod generate; */
1144
1145 /* get info */
1146 xmlSecNssKeyDataRsaGetType, /* xmlSecKeyDataGetTypeMethod getType; */
1147 xmlSecNssKeyDataRsaGetSize, /* xmlSecKeyDataGetSizeMethod getSize; */
1148 NULL((void*)0), /* xmlSecKeyDataGetIdentifier getIdentifier; */
1149
1150 /* read/write */
1151 xmlSecNssKeyDataRsaXmlRead, /* xmlSecKeyDataXmlReadMethod xmlRead; */
1152 xmlSecNssKeyDataRsaXmlWrite, /* xmlSecKeyDataXmlWriteMethod xmlWrite; */
1153 NULL((void*)0), /* xmlSecKeyDataBinReadMethod binRead; */
1154 NULL((void*)0), /* xmlSecKeyDataBinWriteMethod binWrite; */
1155
1156 /* debug */
1157 xmlSecNssKeyDataRsaDebugDump, /* xmlSecKeyDataDebugDumpMethod debugDump; */
1158 xmlSecNssKeyDataRsaDebugXmlDump, /* xmlSecKeyDataDebugDumpMethod debugXmlDump; */
1159
1160 /* reserved for the future */
1161 NULL((void*)0), /* void* reserved0; */
1162 NULL((void*)0), /* void* reserved1; */
1163};
1164
1165/**
1166 * xmlSecNssKeyDataRsaGetKlass:
1167 *
1168 * The RSA key data klass.
1169 *
1170 * Returns: pointer to RSA key data klass.
1171 */
1172xmlSecKeyDataId
1173xmlSecNssKeyDataRsaGetKlass(void) {
1174 return(&xmlSecNssKeyDataRsaKlass);
1175}
1176
1177static int
1178xmlSecNssKeyDataRsaInitialize(xmlSecKeyDataPtr data) {
1179 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1179,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return(-1); }
;
1180
1181 return(xmlSecNssPKIKeyDataInitialize(data));
1182}
1183
1184static int
1185xmlSecNssKeyDataRsaDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) {
1186 xmlSecAssert2(xmlSecKeyDataCheckId(dst, xmlSecNssKeyDataRsaId), -1)if(!( (((( ( dst ) ) != ((void*)0)) && (( ( dst ) )->
id != ((void*)0)) && (( ( dst ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( dst ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( dst
) )->id->name != ((void*)0))) && ((( dst )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1186,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(dst, xmlSecNssKeyDataRsaId)"
, 100, " "); return(-1); }
;
1187 xmlSecAssert2(xmlSecKeyDataCheckId(src, xmlSecNssKeyDataRsaId), -1)if(!( (((( ( src ) ) != ((void*)0)) && (( ( src ) )->
id != ((void*)0)) && (( ( src ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( src ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( src
) )->id->name != ((void*)0))) && ((( src )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1187,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(src, xmlSecNssKeyDataRsaId)"
, 100, " "); return(-1); }
;
1188
1189 return(xmlSecNssPKIKeyDataDuplicate(dst, src));
1190}
1191
1192static void
1193xmlSecNssKeyDataRsaFinalize(xmlSecKeyDataPtr data) {
1194 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1194,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return; }
;
1195
1196 xmlSecNssPKIKeyDataFinalize(data);
1197}
1198
1199static int
1200xmlSecNssKeyDataRsaXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key,
1201 xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
1202 xmlSecKeyDataPtr data = NULL((void*)0);
1203 xmlNodePtr cur;
1204 int ret;
1205 PK11SlotInfo *slot = NULL((void*)0);
1206 SECKEYPublicKey *pubkey=NULL((void*)0);
1207 PRArenaPoolPLArenaPool *arena = NULL((void*)0);
1208
1209 xmlSecAssert2(id == xmlSecNssKeyDataRsaId, -1)if(!( id == xmlSecNssKeyDataRsaGetKlass() ) ) { xmlSecError("pkikeys.c"
,1209,__FUNCTION__, ((void*)0), "id == xmlSecNssKeyDataRsaId"
, 100, " "); return(-1); }
;
1210 xmlSecAssert2(key != NULL, -1)if(!( key != ((void*)0) ) ) { xmlSecError("pkikeys.c",1210,__FUNCTION__
, ((void*)0), "key != NULL", 100, " "); return(-1); }
;
1211 xmlSecAssert2(node != NULL, -1)if(!( node != ((void*)0) ) ) { xmlSecError("pkikeys.c",1211,__FUNCTION__
, ((void*)0), "node != NULL", 100, " "); return(-1); }
;
1212 xmlSecAssert2(keyInfoCtx != NULL, -1)if(!( keyInfoCtx != ((void*)0) ) ) { xmlSecError("pkikeys.c",
1212,__FUNCTION__, ((void*)0), "keyInfoCtx != NULL", 100, " "
); return(-1); }
;
1213
1214 if(xmlSecKeyGetValue(key) != NULL((void*)0)) {
1215 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1215,__FUNCTION__,
1216 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1217 NULL((void*)0),
1218 XMLSEC_ERRORS_R_INVALID_KEY_DATA41,
1219 "key already has a value");
1220 ret = -1;
1221 goto done;
1222 }
1223
1224 slot = xmlSecNssSlotGet(CKM_RSA_PKCS0x00000001);
1225 if(slot == NULL((void*)0)) {
1226 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1226,__FUNCTION__,
1227 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1228 "xmlSecNssSlotGet",
1229 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
1230 "error code=%d", PORT_GetError());
1231 ret = -1;
1232 goto done;
1233 }
1234
1235 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE(2048));
1236 if(arena == NULL((void*)0)) {
1237 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1237,__FUNCTION__,
1238 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1239 "PORT_NewArena",
1240 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
1241 "error code=%d", PORT_GetError());
1242 ret = -1;
1243 goto done;
1244 }
1245
1246 pubkey = (SECKEYPublicKey *)PORT_ArenaZAlloc(arena,
1247 sizeof(SECKEYPublicKey));
1248 if(pubkey == NULL((void*)0) ) {
1249 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1249,__FUNCTION__,
1250 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1251 "PORT_ArenaZAlloc",
1252 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
1253 "error code=%d", PORT_GetError());
1254 PORT_FreeArena(arena, PR_FALSE0);
1255 ret = -1;
1256 goto done;
1257 }
1258 pubkey->arena = arena;
1259 pubkey->keyType = rsaKey;
1260
1261 cur = xmlSecGetNextElementNode(node->children);
1262
1263 /* first is Modulus node. It is REQUIRED because we do not support Seed and PgenCounter*/
1264 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeRSAModulus, xmlSecDSigNs))) {
1265 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1265,__FUNCTION__,
1266 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1267 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
1268 XMLSEC_ERRORS_R_INVALID_NODE21,
1269 "node=%s",
1270 xmlSecErrorsSafeString(xmlSecNodeRSAModulus)(((xmlSecNodeRSAModulus) != ((void*)0)) ? ((char*)(xmlSecNodeRSAModulus
)) : (char*)"NULL")
);
1271 ret = -1;
1272 goto done;
1273 }
1274 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.rsa.modulus)) == NULL((void*)0)) {
1275 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1275,__FUNCTION__,
1276 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1277 "xmlSecNssNodeGetBigNumValue",
1278 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1279 "node=%s",
1280 xmlSecErrorsSafeString(xmlSecNodeRSAModulus)(((xmlSecNodeRSAModulus) != ((void*)0)) ? ((char*)(xmlSecNodeRSAModulus
)) : (char*)"NULL")
);
1281 ret = -1;
1282 goto done;
1283 }
1284 cur = xmlSecGetNextElementNode(cur->next);
1285
1286 /* next is Exponent node. It is REQUIRED because we do not support Seed and PgenCounter*/
1287 if((cur == NULL((void*)0)) || (!xmlSecCheckNodeName(cur, xmlSecNodeRSAExponent, xmlSecDSigNs))) {
1288 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1288,__FUNCTION__,
1289 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1290 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
1291 XMLSEC_ERRORS_R_INVALID_NODE21,
1292 "node=%s",
1293 xmlSecErrorsSafeString(xmlSecNodeRSAExponent)(((xmlSecNodeRSAExponent) != ((void*)0)) ? ((char*)(xmlSecNodeRSAExponent
)) : (char*)"NULL")
);
1294 ret = -1;
1295 goto done;
1296 }
1297 if(xmlSecNssNodeGetBigNumValue(arena, cur, &(pubkey->u.rsa.publicExponent)) == NULL((void*)0)) {
1298 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1298,__FUNCTION__,
1299 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1300 "xmlSecNssNodeGetBigNumValue",
1301 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1302 "node=%s",
1303 xmlSecErrorsSafeString(xmlSecNodeRSAExponent)(((xmlSecNodeRSAExponent) != ((void*)0)) ? ((char*)(xmlSecNodeRSAExponent
)) : (char*)"NULL")
);
1304 ret = -1;
1305 goto done;
1306 }
1307 cur = xmlSecGetNextElementNode(cur->next);
1308
1309 if((cur != NULL((void*)0)) && (xmlSecCheckNodeName(cur, xmlSecNodeRSAPrivateExponent, xmlSecNs))) {
1310 /* next is X node. It is REQUIRED for private key but
1311 * NSS does not support it. We just ignore it */
1312 cur = xmlSecGetNextElementNode(cur->next);
1313 }
1314
1315 if(cur != NULL((void*)0)) {
1316 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1316,__FUNCTION__,
1317 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1318 xmlSecErrorsSafeString(xmlSecNodeGetName(cur))((((((cur)) ? ((const char*)((cur)->name)) : ((void*)0))) !=
((void*)0)) ? ((char*)((((cur)) ? ((const char*)((cur)->name
)) : ((void*)0)))) : (char*)"NULL")
,
1319 XMLSEC_ERRORS_R_INVALID_NODE21,
1320 "no nodes expected");
1321 ret = -1;
1322 goto done;
1323 }
1324
1325 data = xmlSecKeyDataCreate(id);
1326 if(data == NULL((void*)0) ) {
1327 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1327,__FUNCTION__,
1328 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1329 "xmlSecKeyDataCreate",
1330 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1331 XMLSEC_ERRORS_NO_MESSAGE" ");
1332 ret = -1;
1333 goto done;
1334 }
1335
1336 ret = xmlSecNssPKIKeyDataAdoptKey(data, NULL((void*)0), pubkey);
1337 if(ret < 0) {
1338 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1338,__FUNCTION__,
1339 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1340 "xmlSecNssPKIKeyDataAdoptKey",
1341 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1342 XMLSEC_ERRORS_NO_MESSAGE" ");
1343 xmlSecKeyDataDestroy(data);
1344 goto done;
1345 }
1346 pubkey = NULL((void*)0);
1347
1348 ret = xmlSecKeySetValue(key, data);
1349 if(ret < 0) {
1350 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1350,__FUNCTION__,
1351 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1352 "xmlSecKeySetValue",
1353 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1354 XMLSEC_ERRORS_NO_MESSAGE" ");
1355 xmlSecKeyDataDestroy(data);
1356 goto done;
1357 }
1358 data = NULL((void*)0);
1359
1360 ret = 0;
1361
1362done:
1363 if (slot != 0) {
1364 PK11_FreeSlot(slot);
1365 }
1366 if (ret != 0) {
1367 if (pubkey != 0) {
1368 SECKEY_DestroyPublicKey(pubkey);
1369 }
1370 if (data != 0) {
1371 xmlSecKeyDataDestroy(data);
1372 }
1373 }
1374 return(ret);
1375}
1376
1377static int
1378xmlSecNssKeyDataRsaXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key,
1379 xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
1380 xmlSecNssPKIKeyDataCtxPtr ctx;
1381 xmlNodePtr cur;
1382 int ret;
1383
1384 xmlSecAssert2(id == xmlSecNssKeyDataRsaId, -1)if(!( id == xmlSecNssKeyDataRsaGetKlass() ) ) { xmlSecError("pkikeys.c"
,1384,__FUNCTION__, ((void*)0), "id == xmlSecNssKeyDataRsaId"
, 100, " "); return(-1); }
;
1385 xmlSecAssert2(key != NULL, -1)if(!( key != ((void*)0) ) ) { xmlSecError("pkikeys.c",1385,__FUNCTION__
, ((void*)0), "key != NULL", 100, " "); return(-1); }
;
1386 xmlSecAssert2(xmlSecKeyDataCheckId(xmlSecKeyGetValue(key), xmlSecNssKeyDataRsaId), -1)if(!( (((( ( xmlSecKeyGetValue(key) ) ) != ((void*)0)) &&
(( ( xmlSecKeyGetValue(key) ) )->id != ((void*)0)) &&
(( ( xmlSecKeyGetValue(key) ) )->id->klassSize >= sizeof
(xmlSecKeyDataKlass)) && (( ( xmlSecKeyGetValue(key) )
)->id->objSize >= sizeof(xmlSecKeyData)) &&
(( ( xmlSecKeyGetValue(key) ) )->id->name != ((void*)0
))) && ((( xmlSecKeyGetValue(key) )->id) == ( xmlSecNssKeyDataRsaGetKlass
() ))) ) ) { xmlSecError("pkikeys.c",1386,__FUNCTION__, ((void
*)0), "xmlSecKeyDataCheckId(xmlSecKeyGetValue(key), xmlSecNssKeyDataRsaId)"
, 100, " "); return(-1); }
;
1387 xmlSecAssert2(node != NULL, -1)if(!( node != ((void*)0) ) ) { xmlSecError("pkikeys.c",1387,__FUNCTION__
, ((void*)0), "node != NULL", 100, " "); return(-1); }
;
1388 xmlSecAssert2(keyInfoCtx != NULL, -1)if(!( keyInfoCtx != ((void*)0) ) ) { xmlSecError("pkikeys.c",
1388,__FUNCTION__, ((void*)0), "keyInfoCtx != NULL", 100, " "
); return(-1); }
;
1389
1390 ctx = xmlSecNssPKIKeyDataGetCtx(xmlSecKeyGetValue(key))((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(xmlSecKeyGetValue
(key))) + sizeof(xmlSecKeyData)))
;
1391 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",1391,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
1392/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1);*/
1393
1394
1395 if(((xmlSecKeyDataTypePublic0x0001 | xmlSecKeyDataTypePrivate0x0002) & keyInfoCtx->keyReq.keyType) == 0) {
1396 /* we can have only private key or public key */
1397 return(0);
1398 }
1399
1400 /* first is Modulus node */
1401 cur = xmlSecAddChild(node, xmlSecNodeRSAModulus, xmlSecDSigNs);
1402 if(cur == NULL((void*)0)) {
1403 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1403,__FUNCTION__,
1404 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1405 "xmlSecAddChild",
1406 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1407 "node=%s",
1408 xmlSecErrorsSafeString(xmlSecNodeRSAModulus)(((xmlSecNodeRSAModulus) != ((void*)0)) ? ((char*)(xmlSecNodeRSAModulus
)) : (char*)"NULL")
);
1409 return(-1);
1410 }
1411 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.rsa.modulus), 1);
1412 if(ret < 0) {
1413 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1413,__FUNCTION__,
1414 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1415 "xmlSecNssNodeSetBigNumValue",
1416 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1417 "node=%s",
1418 xmlSecErrorsSafeString(xmlSecNodeRSAModulus)(((xmlSecNodeRSAModulus) != ((void*)0)) ? ((char*)(xmlSecNodeRSAModulus
)) : (char*)"NULL")
);
1419 return(-1);
1420 }
1421
1422 /* next is Exponent node. */
1423 cur = xmlSecAddChild(node, xmlSecNodeRSAExponent, xmlSecDSigNs);
1424 if(cur == NULL((void*)0)) {
1425 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1425,__FUNCTION__,
1426 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1427 "xmlSecAddChild",
1428 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1429 "node=%s",
1430 xmlSecErrorsSafeString(xmlSecNodeRSAExponent)(((xmlSecNodeRSAExponent) != ((void*)0)) ? ((char*)(xmlSecNodeRSAExponent
)) : (char*)"NULL")
);
1431 return(-1);
1432 }
1433 ret = xmlSecNssNodeSetBigNumValue(cur, &(ctx->pubkey->u.rsa.publicExponent), 1);
1434 if(ret < 0) {
1435 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1435,__FUNCTION__,
1436 xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id))((((((id)) ? ((id)->name) : ((void*)0))) != ((void*)0)) ? (
(char*)((((id)) ? ((id)->name) : ((void*)0)))) : (char*)"NULL"
)
,
1437 "xmlSecNssNodeSetBigNumValue",
1438 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1439 "node=%s",
1440 xmlSecErrorsSafeString(xmlSecNodeRSAExponent)(((xmlSecNodeRSAExponent) != ((void*)0)) ? ((char*)(xmlSecNodeRSAExponent
)) : (char*)"NULL")
);
1441 return(-1);
1442 }
1443
1444 /* next is PrivateExponent node: not supported in NSS */
1445
1446 return(0);
1447}
1448
1449static int
1450xmlSecNssKeyDataRsaGenerate(xmlSecKeyDataPtr data, xmlSecSizesize_t sizeBits, xmlSecKeyDataType type ATTRIBUTE_UNUSED__attribute__((unused))) {
1451 PK11RSAGenParams params;
1452 PK11SlotInfo *slot = NULL((void*)0);
1453 SECKEYPrivateKey *privkey = NULL((void*)0);
1454 SECKEYPublicKey *pubkey = NULL((void*)0);
1455 int ret = -1;
1456
1457 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId), -1)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1457,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return(-1); }
;
1458 xmlSecAssert2(sizeBits > 0, -1)if(!( sizeBits > 0 ) ) { xmlSecError("pkikeys.c",1458,__FUNCTION__
, ((void*)0), "sizeBits > 0", 100, " "); return(-1); }
;
1459
1460 params.keySizeInBits = sizeBits;
1461 params.pe = 65537;
1462
1463 slot = xmlSecNssSlotGet(CKM_RSA_PKCS_KEY_PAIR_GEN0x00000000);
1464 PK11_Authenticate(slot, PR_TRUE1, NULL((void*)0) /* default pwd callback */);
1465 privkey = PK11_GenerateKeyPair(slot, CKM_RSA_PKCS_KEY_PAIR_GEN0x00000000, &params,
1466 &pubkey, PR_FALSE0, PR_TRUE1, NULL((void*)0));
1467
1468 if(privkey == NULL((void*)0) || pubkey == NULL((void*)0)) {
1469 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1469,__FUNCTION__,
1470 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
1471 "PK11_GenerateKeyPair",
1472 XMLSEC_ERRORS_R_CRYPTO_FAILED4,
1473 "error code=%d", PORT_GetError());
1474
1475 goto done;
1476 }
1477
1478 ret = xmlSecNssPKIKeyDataAdoptKey(data, privkey, pubkey);
1479 if(ret < 0) {
1480 xmlSecError(XMLSEC_ERRORS_HERE"pkikeys.c",1480,__FUNCTION__,
1481 xmlSecErrorsSafeString(xmlSecKeyDataGetName(data))(((((((( (data) ) != ((void*)0)) && (( (data) )->id
!= ((void*)0)) && (( (data) )->id->klassSize >=
sizeof(xmlSecKeyDataKlass)) && (( (data) )->id->
objSize >= sizeof(xmlSecKeyData)) && (( (data) )->
id->name != ((void*)0)))) ? ((((data)->id)) ? (((data)->
id)->name) : ((void*)0)) : ((void*)0))) != ((void*)0)) ? (
(char*)(((((( (data) ) != ((void*)0)) && (( (data) )->
id != ((void*)0)) && (( (data) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( (data) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( (data
) )->id->name != ((void*)0)))) ? ((((data)->id)) ? (
((data)->id)->name) : ((void*)0)) : ((void*)0)))) : (char
*)"NULL")
,
1482 "xmlSecNssPKIKeyDataAdoptKey",
1483 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
1484 XMLSEC_ERRORS_NO_MESSAGE" ");
1485 goto done;
1486 }
1487
1488 ret = 0;
1489
1490done:
1491 if (slot != NULL((void*)0)) {
1492 PK11_FreeSlot(slot);
1493 }
1494 if (ret == 0) {
1495 return (0);
1496 }
1497
1498 if (pubkey != NULL((void*)0)) {
1499 SECKEY_DestroyPublicKey(pubkey);
1500 }
1501 if (privkey != NULL((void*)0)) {
1502 SECKEY_DestroyPrivateKey(privkey);
1503 }
1504 return(-1);
1505}
1506
1507static xmlSecKeyDataType
1508xmlSecNssKeyDataRsaGetType(xmlSecKeyDataPtr data) {
1509 xmlSecNssPKIKeyDataCtxPtr ctx;
1510
1511 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId), xmlSecKeyDataTypeUnknown)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1511,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return(0x0000); }
;
1512
1513 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
1514 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",1514,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
1515 xmlSecAssert2(ctx->pubkey == NULL || SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1)if(!( ctx->pubkey == ((void*)0) || SECKEY_GetPublicKeyType
(ctx->pubkey) == rsaKey ) ) { xmlSecError("pkikeys.c",1515
,__FUNCTION__, ((void*)0), "ctx->pubkey == NULL || SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey"
, 100, " "); return(-1); }
;
1516 if (ctx->privkey != NULL((void*)0)) {
1517 return(xmlSecKeyDataTypePrivate0x0002 | xmlSecKeyDataTypePublic0x0001);
1518 } else {
1519 return(xmlSecKeyDataTypePublic0x0001);
1520 }
1521
1522 return(xmlSecKeyDataTypeUnknown0x0000);
1523}
1524
1525static xmlSecSizesize_t
1526xmlSecNssKeyDataRsaGetSize(xmlSecKeyDataPtr data) {
1527 xmlSecNssPKIKeyDataCtxPtr ctx;
1528
1529 xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId), 0)if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1529,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return(0); }
;
1530
1531 ctx = xmlSecNssPKIKeyDataGetCtx(data)((xmlSecNssPKIKeyDataCtxPtr)(((unsigned char*)(data)) + sizeof
(xmlSecKeyData)))
;
1532 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("pkikeys.c",1532,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
1533/* xmlSecAssert2(SECKEY_GetPublicKeyType(ctx->pubkey) == rsaKey, -1);*/
1534
1535 return(8 * SECKEY_PublicKeyStrength(ctx->pubkey));
1536}
1537
1538static void
1539xmlSecNssKeyDataRsaDebugDump(xmlSecKeyDataPtr data, FILE* output) {
1540 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1540,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return; }
;
1541 xmlSecAssert(output != NULL)if(!( output != ((void*)0) ) ) { xmlSecError("pkikeys.c",1541
,__FUNCTION__, ((void*)0), "output != NULL", 100, " "); return
; }
;
1542
1543 fprintf(output, "=== rsa key: size = %d\n",
1544 xmlSecNssKeyDataRsaGetSize(data));
1545}
1546
1547static void
1548xmlSecNssKeyDataRsaDebugXmlDump(xmlSecKeyDataPtr data, FILE* output) {
1549 xmlSecAssert(xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId))if(!( (((( ( data ) ) != ((void*)0)) && (( ( data ) )
->id != ((void*)0)) && (( ( data ) )->id->klassSize
>= sizeof(xmlSecKeyDataKlass)) && (( ( data ) )->
id->objSize >= sizeof(xmlSecKeyData)) && (( ( data
) )->id->name != ((void*)0))) && ((( data )->
id) == ( xmlSecNssKeyDataRsaGetKlass() ))) ) ) { xmlSecError(
"pkikeys.c",1549,__FUNCTION__, ((void*)0), "xmlSecKeyDataCheckId(data, xmlSecNssKeyDataRsaId)"
, 100, " "); return; }
;
1550 xmlSecAssert(output != NULL)if(!( output != ((void*)0) ) ) { xmlSecError("pkikeys.c",1550
,__FUNCTION__, ((void*)0), "output != NULL", 100, " "); return
; }
;
1551
1552 fprintf(output, "<RSAKeyValue size=\"%d\" />\n",
1553 xmlSecNssKeyDataRsaGetSize(data));
1554}
1555
1556#endif /* XMLSEC_NO_RSA */
1557
1558
1559