Add SDR Context resource to hold information during processing of

SDR encrypt, decrypt and change password commands.  These changes
enable use of the context field of the SDR messages by clients.
This commit is contained in:
thayes%netscape.com 2000-08-22 01:16:42 +00:00
Родитель 67da52ab59
Коммит 4b809a5c35
5 изменённых файлов: 273 добавлений и 35 удалений

Просмотреть файл

@ -57,6 +57,7 @@ CSRCS = \
autorenewal.c \
derprint.c \
msgthread.c \
sdrres.c \
$(NULL)
RESNAME = psm.rc

Просмотреть файл

@ -54,6 +54,7 @@
#include "protocolshr.h"
#include "msgthread.h"
#include "pk11sdr.h"
#include "sdrres.h"
#define SSL_SC_RSA 0x00000001L
#define SSL_SC_MD2 0x00000010L
@ -140,39 +141,47 @@ sdrencrypt(SSMControlConnection *ctrl, SECItem *msg)
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
EncryptRequestMessage request;
EncryptReplyMessage reply;
void *ctx;
SECStatus s;
SSMResourceID id;
SSMResource *res = NULL;
SSM_DEBUG("sdrEncrypt\n");
request.keyid.data = 0;
request.data.data = 0;
request.ctx.data = 0;
request.keyid.data = NULL;
request.data.data = NULL;
request.ctx.data = NULL;
reply.item.data = 0;
/* Make sure user has initialized database password */
if (PK11_NeedUserInit(slot)) {
SSM_DEBUG("Calling SSM_SetUserPassword\n");
rv = SSM_SetUserPassword(slot, &ctrl->super.super);
SSM_DEBUG("SSM_SetUserPassword returns %d\n", rv);
if (rv != SSM_SUCCESS) { rv = SSM_ERR_NEED_USER_INIT_DB; goto loser; }
}
if (PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, ctrl) != SECSuccess) {
rv = SSM_ERR_BAD_DB_PASSWORD;
goto loser;
}
reply.item.data = NULL;
/* Decode the message (frees message data) */
crv = CMT_DecodeMessage(EncryptRequestTemplate, &request, (CMTItem*)msg);
if (crv != CMTSuccess) { rv = SSM_FAILURE; goto loser; }
/* ctx = CMT_CopyItemToPtr(request.ctx); need to put this in an resource */
ctx = 0;
/* Create a resource for handling UI events */
rv = SSM_CreateResource(SSM_RESTYPE_SDR_CONTEXT, 0, ctrl, &id, &res);
if (rv != SSM_SUCCESS) goto loser;
/* Set client context field for UI events
* NOTE: the resource will be deleted before the request data
* is freed
*/
res->m_clientContext = request.ctx;
/* Make sure user has initialized database password */
if (PK11_NeedUserInit(slot)) {
SSM_DEBUG("Calling SSM_SetUserPassword\n");
rv = SSM_SetUserPassword(slot, res);
SSM_DEBUG("SSM_SetUserPassword returns %d\n", rv);
if (rv != SSM_SUCCESS) { rv = SSM_ERR_NEED_USER_INIT_DB; goto loser; }
}
if (PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, res) != SECSuccess) {
rv = SSM_ERR_BAD_DB_PASSWORD;
goto loser;
}
s = PK11SDR_Encrypt((SECItem*)&request.keyid, (SECItem*)&request.data,
(SECItem*)&reply.item, ctx);
(SECItem*)&reply.item, res);
SSM_DEBUG("Encrypt returns %d\n", s);
SSM_DEBUG(" -> Item: %lx (%d)\n", reply.item.data, reply.item.len);
@ -182,10 +191,11 @@ sdrencrypt(SSMControlConnection *ctrl, SECItem *msg)
if (crv != CMTSuccess) { rv = SSM_FAILURE; goto loser; /* Unknown error */ }
loser:
if (request.keyid.data) free(request.keyid.data);
if (request.data.data) free(request.data.data);
if (request.ctx.data) free(request.ctx.data);
if (reply.item.data) free(reply.item.data);
if (res) SSM_FreeResource(res);
if (request.keyid.data) PR_Free(request.keyid.data);
if (request.data.data) PR_Free(request.data.data);
if (request.ctx.data) PR_Free(request.ctx.data);
if (reply.item.data) PR_Free(reply.item.data);
return rv;
}
@ -198,21 +208,34 @@ sdrdecrypt(SSMControlConnection *ctrl, SECItem *msg)
SECStatus s;
DecryptRequestMessage request;
DecryptReplyMessage reply;
SSMResourceID id;
SSMResource *res = NULL;
request.data.data = 0;
request.ctx.data = 0;
request.data.data = NULL;
request.ctx.data = NULL;
reply.item.data = NULL;
SSM_DEBUG("sdrDecrypt\n");
crv = CMT_DecodeMessage(DecryptRequestTemplate, &request, (CMTItem*)msg);
if (crv != CMTSuccess) { rv = SSM_FAILURE; goto loser; }
if (PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, ctrl) != SECSuccess) {
/* Create a resource for handling UI events */
rv = SSM_CreateResource(SSM_RESTYPE_SDR_CONTEXT, 0, ctrl, &id, &res);
if (rv != SSM_SUCCESS) goto loser;
/* Set client context field for UI events
* NOTE: the resource will be deleted before the request data
* is freed
*/
res->m_clientContext = request.ctx;
if (PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, res) != SECSuccess) {
rv = SSM_ERR_BAD_DB_PASSWORD;
goto loser;
}
s = PK11SDR_Decrypt((SECItem*)&request.data, (SECItem*)&reply.item, 0);
s = PK11SDR_Decrypt((SECItem*)&request.data, (SECItem*)&reply.item, res);
if (s != SECSuccess) { rv = SSM_FAILURE; goto loser; }
msg->type = SSM_SDR_DECRYPT_REPLY;
@ -220,9 +243,10 @@ sdrdecrypt(SSMControlConnection *ctrl, SECItem *msg)
if (crv != CMTSuccess) { rv = SSM_FAILURE; goto loser; /* Unknown error */ }
loser:
if (request.data.data) free(request.data.data);
if (request.ctx.data) free(request.ctx.data);
if (reply.item.data) free(reply.item.data);
if (res) SSM_FreeResource(res);
if (request.data.data) PR_Free(request.data.data);
if (request.ctx.data) PR_Free(request.ctx.data);
if (reply.item.data) PR_Free(reply.item.data);
return rv;
}
@ -233,6 +257,8 @@ sdrChangePassword(SSMControlConnection *ctrl, SECItem *msg)
SSMStatus rv = SSM_SUCCESS;
SingleItemMessage req;
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
SSMResourceID id;
SSMResource *res = NULL;
SSM_DEBUG("sdrChangePassword\n");
@ -243,13 +269,22 @@ sdrChangePassword(SSMControlConnection *ctrl, SECItem *msg)
goto loser;
}
/* Should decode the item here to get context */
/* Create a resource for handling UI events */
rv = SSM_CreateResource(SSM_RESTYPE_SDR_CONTEXT, 0, ctrl, &id, &res);
if (rv != SSM_SUCCESS) goto loser;
/* Set client context field for UI events
* NOTE: the resource will be deleted before the request data
* is freed
*/
res->m_clientContext = req.item;
/* Invoke the UI for setting password */
rv = SSM_SetUserPassword(slot, &ctrl->super.super);
rv = SSM_SetUserPassword(slot, res);
loser:
if (req.item.data) free(req.item.data);
if (res) SSM_FreeResource(res);
if (req.item.data) PR_Free(req.item.data);
return rv;
}

Просмотреть файл

@ -53,6 +53,7 @@
#include "advisor.h"
#include "p12res.h"
#include "signtextres.h"
#include "sdrres.h"
#include <stdarg.h>
@ -356,6 +357,21 @@ SSM_ResourceInit()
NULL,
SSMSignTextResource_Print,
SSMSignTextResource_FormSubmitHandler);
SSM_RegisterResourceType("SDR Context",
SSM_RESTYPE_SDR_CONTEXT,
SSM_RESTYPE_RESOURCE,
SSM_CLIENTDEST_FREE,
SSMSDRContext_Create,
SSMSDRContext_Destroy,
NULL, /* Shutdown */
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SSMSDRContext_FormSubmitHandler);
}
return rv;

Просмотреть файл

@ -0,0 +1,119 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Netscape security libraries.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL"), in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your
* version of this file only under the terms of the GPL and not to
* allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient
* may use your version of this file under either the MPL or the
* GPL.
*/
#include "resource.h"
#include "minihttp.h"
#include "advisor.h"
#include "sdrres.h"
#define SSMRESOURCE(object) (&(object)->super)
/*
* SDRContext_Create
* Create and initialize an SDR context resource object
*/
SSMStatus
SSMSDRContext_Create(void *arg, SSMControlConnection *ctrl, SSMResource **res)
{
SSMStatus rv = SSM_SUCCESS;
SSMSDRContext *sdr = 0;
*res = NULL;
sdr = SSM_ZNEW(SSMSDRContext);
if (sdr == NULL) { rv = SSM_FAILURE; goto done; }
rv = SSMResource_Init(ctrl, SSMRESOURCE(sdr), SSM_RESTYPE_SDR_CONTEXT);
if (rv != SSM_SUCCESS) goto done;
/* Init SDR fields here */
/* Return the new value */
*res = SSMRESOURCE(sdr);
sdr = NULL;
done:
if (sdr) SSM_FreeResource(SSMRESOURCE(sdr));
SSM_DEBUG("SDRContext_Create (%d) %lx\n", rv, *res);
return rv;
}
/*
* SDRContext_Destroy
* Destroy contents of resource and optionally free the memory.
* NOTE: doFree should always be PR_TRUE, since this type is not
* subclassed.
*/
SSMStatus
SSMSDRContext_Destroy(SSMResource *res, PRBool doFree)
{
SSMStatus rv;
SSMSDRContext *sdr = (SSMSDRContext *)res;
rv = SSMResource_Destroy(res, PR_FALSE);
if (rv != SSM_SUCCESS) goto done;
if (doFree) PR_Free(sdr);
done:
SSM_DEBUG("SDRContext_Destroy (%d)\n", rv);
return rv;
}
/*
* SSMSDRContext_FormSubmitHandler
*/
SSMSDRContext_FormSubmitHandler(SSMResource * res, HTTPRequest * req)
{
SSMStatus rv;
SSM_DEBUG("SSMSDRContext_FormSubmit\n");
if (!res->m_formName)
goto loser;
if (PL_strcmp(res->m_formName, "set_db_password") == 0)
rv = SSM_SetDBPasswordHandler(req);
else /* other cases where this could be used will go here */
goto loser;
SSM_DEBUG("SSMSDRContext_FormSubmit (%d)\n", rv);
return rv;
loser:
SSM_DEBUG("FormSubmit handler is called with no valid formName\n");
SSM_NotifyUIEvent(res);
return SSM_FAILURE;
}

Просмотреть файл

@ -0,0 +1,67 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Netscape security libraries.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL"), in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your
* version of this file only under the terms of the GPL and not to
* allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient
* may use your version of this file under either the MPL or the
* GPL.
*/
#ifndef SDRRES_H_
#define SDRRES_H_
/* Include resource types - SSM_RESTYPE_SDR_CONTEXT in particular */
#include "rsrcids.h"
/*
* SSMSDRContext
* A PSM server resource to be used when performing SDR
* operations. This resource has type SSM_RESTYPE_SDR_CONTEXT.
*/
typedef struct SSMSDRContext SSMSDRContext;
struct SSMSDRContext {
SSMResource super;
};
/*
* Declare create and destroy functions
*/
SSMStatus
SSMSDRContext_Create(void *arg, SSMControlConnection *ctrl, SSMResource **res);
SSMStatus
SSMSDRContext_Destroy(SSMResource *res, PRBool doFree);
/* Init method would be here. However we are not allowing subclassing
* at the current time.
*/
SSMStatus
SSMSDRContext_FormSubmitHandler(SSMResource * res, HTTPRequest * req);
#endif /* SDRRES_H_ */