зеркало из https://github.com/mozilla/gecko-dev.git
Merge changes from SDR_BRANCH.
Add more SDR features, and provide compatibility between older PSM servers and this client library.
This commit is contained in:
Родитель
cda9986f5c
Коммит
d1e4df651d
|
@ -381,6 +381,10 @@ void CMT_SavePrefs(PCMT_CONTROL cm_control, CMTItem* eventData)
|
|||
void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData)
|
||||
{
|
||||
CMUint32 eventType;
|
||||
CMTItem msgCopy;
|
||||
|
||||
/* Init the msgCopy */
|
||||
msgCopy.data = 0;
|
||||
|
||||
/* Get the event type */
|
||||
if ((eventData->type & SSM_CATEGORY_MASK) != SSM_EVENT_MESSAGE) {
|
||||
|
@ -399,9 +403,23 @@ void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData)
|
|||
UIEvent event;
|
||||
void * clientContext = NULL;
|
||||
|
||||
/* Copy the message to allow a second try with the old format */
|
||||
msgCopy.len = eventData->len;
|
||||
msgCopy.data = calloc(msgCopy.len, 1);
|
||||
if (msgCopy.data) {
|
||||
memcpy(msgCopy.data, eventData->data, eventData->len);
|
||||
}
|
||||
|
||||
/* Get the event data first */
|
||||
if (CMT_DecodeMessage(UIEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
/* Attempt to decode using the old format. Modal is True */
|
||||
if (!msgCopy.data ||
|
||||
CMT_DecodeMessage(OldUIEventTemplate, &event, &msgCopy) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set default modal value */
|
||||
event.isModal = CM_TRUE;
|
||||
}
|
||||
|
||||
/* Convert the client context to a pointer */
|
||||
|
@ -456,6 +474,7 @@ void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData)
|
|||
}
|
||||
loser:
|
||||
free(eventData->data);
|
||||
free(msgCopy.data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,30 +40,22 @@
|
|||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "protocolshr.h"
|
||||
#include "rsrcids.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Encrypt request */
|
||||
typedef struct EncryptRequestMessage
|
||||
#undef PROCESS_LOCALLY
|
||||
|
||||
/* Encryption result - contains the key id and the resulting data */
|
||||
/* An empty key id indicates that NO encryption was performed */
|
||||
typedef struct EncryptionResult
|
||||
{
|
||||
CMTItem keyid; /* May have length 0 for default */
|
||||
CMTItem keyid;
|
||||
CMTItem data;
|
||||
} EncryptRequestMessage;
|
||||
|
||||
static CMTMessageTemplate EncryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, keyid) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, data) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/* Encrypt reply message - SingleItemMessage */
|
||||
/* Decrypt request message - SingleItemMessage */
|
||||
/* Decrypt reply message - SingleItemMessage */
|
||||
} EncryptionResult;
|
||||
|
||||
/* Constants for testing */
|
||||
static const char *kPrefix = "Encrypted:";
|
||||
static const char *kFailure = "Failure:";
|
||||
|
||||
static CMTItem
|
||||
CMT_CopyDataToItem(const unsigned char *data, CMUint32 len)
|
||||
|
@ -77,104 +69,19 @@ CMT_CopyDataToItem(const unsigned char *data, CMUint32 len)
|
|||
return item;
|
||||
}
|
||||
|
||||
/* encryption request */
|
||||
static CMTStatus
|
||||
tmp_DoEncryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
EncryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.keyid.data = 0;
|
||||
request.data.data = 0;
|
||||
|
||||
/* Decode incoming message */
|
||||
rv = CMT_DecodeMessage(EncryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser; /* Protocol error */
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Encrypt" by prefixing the data */
|
||||
reply.item.len = request.data.len + pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (pLen) memcpy(reply.item.data, kPrefix, pLen);
|
||||
memcpy(&reply.item.data[pLen], request.data.data, request.data.len);
|
||||
|
||||
/* Generate response */
|
||||
message->type = SSM_SDR_ENCRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(SingleItemMessageTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser; /* Unknown error */
|
||||
|
||||
loser:
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* decryption request */
|
||||
static CMTStatus
|
||||
tmp_DoDecryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
SingleItemMessage request;
|
||||
SingleItemMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.item.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode the message */
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Decrypt" the message by removing the key */
|
||||
if (pLen && memcmp(request.item.data, kPrefix, pLen) != 0) {
|
||||
rv = CMTFailure; /* Invalid format */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
reply.item.len = request.item.len - pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) { rv = CMTFailure; goto loser; }
|
||||
|
||||
memcpy(reply.item.data, &request.item.data[pLen], reply.item.len);
|
||||
|
||||
/* Create reply message */
|
||||
message->type = SSM_SDR_DECRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(SingleItemMessageTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
loser:
|
||||
if (request.item.data) free(request.item.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
tmp_SendMessage(PCMT_CONTROL control, CMTItem *message)
|
||||
{
|
||||
#ifndef PROCESS_LOCALLY
|
||||
return CMT_SendMessage(control, message);
|
||||
#else
|
||||
if (message->type == SSM_SDR_ENCRYPT_REQUEST)
|
||||
return tmp_DoEncryptionRequest(message);
|
||||
return CMT_DoEncryptionRequest(message);
|
||||
else if (message->type == SSM_SDR_DECRYPT_REQUEST)
|
||||
return tmp_DoDecryptionRequest(message);
|
||||
return CMT_DoDecryptionRequest(message);
|
||||
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
/* End test code */
|
||||
|
||||
|
@ -183,6 +90,7 @@ CMT_SDREncrypt(PCMT_CONTROL control, const unsigned char *key, CMUint32 keyLen,
|
|||
const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem message;
|
||||
EncryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
@ -191,8 +99,14 @@ CMT_SDREncrypt(PCMT_CONTROL control, const unsigned char *key, CMUint32 keyLen,
|
|||
request.keyid = CMT_CopyDataToItem(key, keyLen);
|
||||
request.data = CMT_CopyDataToItem(data, dataLen);
|
||||
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
if (CMT_EncodeMessage(EncryptRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
rv = CMT_EncodeMessage(EncryptRequestTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
|
@ -200,11 +114,13 @@ CMT_SDREncrypt(PCMT_CONTROL control, const unsigned char *key, CMUint32 keyLen,
|
|||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
if (tmp_SendMessage(control, &message) != CMTSuccess) goto loser;
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_ENCRYPT_REPLY) goto loser;
|
||||
if (message.type != SSM_SDR_ENCRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess)
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
|
@ -218,22 +134,28 @@ loser:
|
|||
if (request.data.data) free(request.data.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return CMTSuccess; /* need return value */
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SDRDecrypt(PCMT_CONTROL control, const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMTItem message;
|
||||
SingleItemMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.item = CMT_CopyDataToItem(data, dataLen);
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
if (CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
rv = CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
|
@ -241,11 +163,13 @@ CMT_SDRDecrypt(PCMT_CONTROL control, const unsigned char *data, CMUint32 dataLen
|
|||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
if (tmp_SendMessage(control, &message) != CMTSuccess) goto loser;
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_DECRYPT_REPLY) goto loser;
|
||||
if (message.type != SSM_SDR_DECRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess)
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
|
@ -258,6 +182,5 @@ loser:
|
|||
if (request.item.data) free(request.item.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return CMTSuccess; /* need return value */
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ EXPORTS = \
|
|||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
|
@ -57,6 +58,7 @@ EXPORTS = \
|
|||
|
||||
CSRCS = newproto.c \
|
||||
templates.c \
|
||||
protocolshr.c \
|
||||
obscure.c \
|
||||
obspriv.c \
|
||||
$(NULL)
|
||||
|
|
|
@ -84,6 +84,7 @@ OBJS= \
|
|||
.\$(OBJDIR)\templates.obj \
|
||||
.\$(OBJDIR)\obscure.obj \
|
||||
.\$(OBJDIR)\obspriv.obj \
|
||||
.\$(OBJDIR)\protocolshr.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
|
@ -104,6 +105,7 @@ INSTALL_FILE_LIST= protocol.h \
|
|||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
|
|
|
@ -38,6 +38,7 @@ EXPORTS = \
|
|||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
|
@ -47,6 +48,7 @@ EXPORTS = \
|
|||
|
||||
MODULE = security
|
||||
CSRCS = newproto.c \
|
||||
protocolshr.c \
|
||||
templates.c \
|
||||
obscure.c \
|
||||
obspriv.c \
|
||||
|
|
|
@ -135,6 +135,7 @@ typedef struct UIEvent {
|
|||
} UIEvent;
|
||||
|
||||
extern CMTMessageTemplate UIEventTemplate[];
|
||||
extern CMTMessageTemplate OldUIEventTemplate[];
|
||||
|
||||
typedef struct TaskCompletedEvent {
|
||||
CMInt32 resourceID;
|
||||
|
@ -594,4 +595,21 @@ typedef struct HTMLCertInfoRequest {
|
|||
|
||||
extern CMTMessageTemplate HTMLCertInfoRequestTemplate[];
|
||||
|
||||
typedef struct EncryptRequestMessage
|
||||
{
|
||||
CMTItem keyid; /* May have length 0 for default */
|
||||
CMTItem data;
|
||||
} EncryptRequestMessage;
|
||||
|
||||
extern CMTMessageTemplate EncryptRequestTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage EncryptReplyMessage;
|
||||
#define EncryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
typedef struct SingleItemMessage DecryptRequestMessage;
|
||||
#define DecryptRequestTemplate SingleItemMessageTemplate
|
||||
|
||||
typedef struct SingleItemMessage DecryptReplyMessage;
|
||||
#define DecryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
#endif /* __MESSAGES_H__ */
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* 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 "string.h"
|
||||
#include "protocol.h"
|
||||
#include "protocolshr.h"
|
||||
#include "messages.h"
|
||||
|
||||
/* Forward ref */
|
||||
static void encrypt(CMTItem *data);
|
||||
static void decrypt(CMTItem *data);
|
||||
|
||||
const char *kPrefix = "Encrypted";
|
||||
|
||||
/* encryption request */
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
EncryptRequestMessage request;
|
||||
EncryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.keyid.data = 0;
|
||||
request.data.data = 0;
|
||||
|
||||
/* Decode incoming message */
|
||||
rv = CMT_DecodeMessage(EncryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser; /* Protocol error */
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Encrypt" by prefixing the data */
|
||||
reply.item.len = request.data.len + pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (pLen) memcpy(reply.item.data, kPrefix, pLen);
|
||||
encrypt(&request.data);
|
||||
memcpy(&reply.item.data[pLen], request.data.data, request.data.len);
|
||||
|
||||
/* Generate response */
|
||||
message->type = SSM_SDR_ENCRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(EncryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser; /* Unknown error */
|
||||
|
||||
loser:
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* decryption request */
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
DecryptRequestMessage request;
|
||||
DecryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.item.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode the message */
|
||||
rv = CMT_DecodeMessage(DecryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Decrypt" the message by removing the key */
|
||||
if (pLen && memcmp(request.item.data, kPrefix, pLen) != 0) {
|
||||
rv = CMTFailure; /* Invalid format */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
reply.item.len = request.item.len - pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) { rv = CMTFailure; goto loser; }
|
||||
|
||||
memcpy(reply.item.data, &request.item.data[pLen], reply.item.len);
|
||||
decrypt(&reply.item);
|
||||
|
||||
/* Create reply message */
|
||||
message->type = SSM_SDR_DECRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(DecryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
loser:
|
||||
if (request.item.data) free(request.item.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* "encrypt" */
|
||||
static unsigned char mask[64] = {
|
||||
0x73, 0x46, 0x1a, 0x05, 0x24, 0x65, 0x43, 0xb4, 0x24, 0xee, 0x79, 0xc1, 0xcc,
|
||||
0x49, 0xc7, 0x27, 0x11, 0x91, 0x2e, 0x8f, 0xaa, 0xf7, 0x62, 0x75, 0x41, 0x7e,
|
||||
0xb2, 0x42, 0xde, 0x1b, 0x42, 0x7b, 0x1f, 0x33, 0x49, 0xca, 0xd1, 0x6a, 0x85,
|
||||
0x05, 0x6c, 0xf9, 0x0e, 0x3e, 0x72, 0x02, 0xf2, 0xd8, 0x9d, 0xa1, 0xb8, 0x6e,
|
||||
0x03, 0x18, 0x3e, 0x82, 0x86, 0x34, 0x1a, 0x61, 0xd9, 0x65, 0xb6, 0x7f
|
||||
};
|
||||
|
||||
static void
|
||||
encrypt(CMTItem *data)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
j = 0;
|
||||
for(i = 0;i < data->len;i++)
|
||||
{
|
||||
data->data[i] ^= mask[j];
|
||||
|
||||
if (++j >= 64) j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
decrypt(CMTItem *data)
|
||||
{
|
||||
encrypt(data);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
protocolshr.h - Definitions of shared routines for both client and server
|
||||
These are mostly for testing.
|
||||
*/
|
||||
|
||||
#ifndef __PROTOCOLSHR_H__
|
||||
#define __PROTOCOLSHR_H__
|
||||
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message);
|
||||
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *meessage);
|
||||
|
||||
|
||||
#endif /* __PROTOCOLSHR_H__ */
|
|
@ -135,6 +135,21 @@ CMTMessageTemplate UIEventTemplate[] =
|
|||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/*
|
||||
* The old UI Event was missing the modal indication.
|
||||
* As a transition aid, we use the old template if the
|
||||
* "modern" version doesn't work. Model is true in that case
|
||||
*/
|
||||
CMTMessageTemplate OldUIEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UIEvent, resourceID) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, width) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, height) },
|
||||
{ CMT_DT_STRING, offsetof(UIEvent, url) },
|
||||
{ CMT_DT_ITEM, offsetof(UIEvent, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TaskCompletedEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, resourceID) },
|
||||
|
@ -596,3 +611,10 @@ CMTMessageTemplate HTMLCertInfoRequestTemplate[] =
|
|||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, showIssuer) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate EncryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, keyid) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, data) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
|
|
@ -56,6 +56,7 @@ CSRCS = \
|
|||
main.c \
|
||||
autorenewal.c \
|
||||
derprint.c \
|
||||
msgthread.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
/* Cartman Server specific includes */
|
||||
#include "serv.h"
|
||||
#include "ctrlconn.h"
|
||||
#include "msgthread.h"
|
||||
|
||||
struct MsgThreadCtx
|
||||
{
|
||||
SSMStatus (*f)(SSMControlConnection *, SECItem *);
|
||||
SSMControlConnection *ctrl;
|
||||
SECItem *msg;
|
||||
};
|
||||
typedef struct MsgThreadCtx MsgThreadCtx;
|
||||
|
||||
static void
|
||||
freectx(MsgThreadCtx *ctx)
|
||||
{
|
||||
if (!ctx) return;
|
||||
|
||||
SSM_FreeResource(&ctx->ctrl->super.super);
|
||||
SECITEM_FreeItem(ctx->msg, PR_TRUE);
|
||||
PR_Free(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
SSMStatus rv;
|
||||
MsgThreadCtx *ctx = (MsgThreadCtx*)arg;
|
||||
|
||||
rv = ctx->f(ctx->ctrl, ctx->msg);
|
||||
if (rv != SSM_SUCCESS) {
|
||||
ssmcontrolconnection_encode_err_reply(ctx->msg, rv);
|
||||
}
|
||||
|
||||
ssmcontrolconnection_send_message_to_client(ctx->ctrl, ctx->msg);
|
||||
|
||||
freectx(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function frees the Control Connection and the Message
|
||||
* data before returning.
|
||||
*/
|
||||
SSMStatus
|
||||
SSM_ProcessMsgOnThread(SSMStatus (*f)(SSMControlConnection *, SECItem *),
|
||||
SSMControlConnection *ctrl, SECItem *msg)
|
||||
{
|
||||
SSMStatus rv = PR_SUCCESS;
|
||||
MsgThreadCtx *ctx = 0;
|
||||
PRThread *thrd;
|
||||
|
||||
ctx = (MsgThreadCtx*)PR_Malloc(sizeof (MsgThreadCtx));
|
||||
if (!ctx) { rv = PR_FAILURE; goto loser; }
|
||||
|
||||
ctx->f = f;
|
||||
ctx->ctrl = ctrl;
|
||||
SSM_GetResourceReference(&ctrl->super.super);
|
||||
ctx->msg = SECITEM_DupItem(msg);
|
||||
|
||||
thrd = PR_CreateThread(PR_USER_THREAD, threadfunc, ctx, PR_PRIORITY_NORMAL,
|
||||
PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
|
||||
if (!thrd) goto loser;
|
||||
|
||||
ctx = 0; /* Thread now owns the context */
|
||||
|
||||
loser:
|
||||
if (ctx) freectx(ctx);
|
||||
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 _MSGTHREAD_H_
|
||||
#define _MSGTHREAD_H_
|
||||
|
||||
#include "serv.h"
|
||||
|
||||
SSMStatus
|
||||
SSM_ProcessMsgOnThread(SSMStatus (*f)(SSMControlConnection *, SECItem *),
|
||||
SSMControlConnection *ctrl, SECItem *msg);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -51,6 +51,9 @@
|
|||
#include "signtextres.h"
|
||||
#include "advisor.h"
|
||||
#include "ssl.h"
|
||||
#include "protocolshr.h"
|
||||
#include "msgthread.h"
|
||||
#include "pk11func.h"
|
||||
|
||||
#define SSL_SC_RSA 0x00000001L
|
||||
#define SSL_SC_MD2 0x00000010L
|
||||
|
@ -127,6 +130,47 @@ loser:
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* Thread functions for SDR_ENCRYPT */
|
||||
static SSMStatus
|
||||
sdrencrypt(SSMControlConnection *ctrl, SECItem *msg)
|
||||
{
|
||||
SSMStatus rv = SSM_SUCCESS;
|
||||
CMTStatus crv;
|
||||
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
|
||||
|
||||
/* Make sure user has initialized database password */
|
||||
if (PK11_NeedUserInit(slot)) {
|
||||
rv = SSM_SetUserPassword(slot, &ctrl->super.super);
|
||||
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;
|
||||
}
|
||||
|
||||
if (CMT_DoEncryptionRequest(msg) != CMTSuccess) { rv = SSM_FAILURE; goto loser; }
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
static SSMStatus
|
||||
sdrdecrypt(SSMControlConnection *ctrl, SECItem *msg)
|
||||
{
|
||||
SSMStatus rv = PR_SUCCESS;
|
||||
|
||||
if (PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, ctrl) != SECSuccess) {
|
||||
rv = SSM_ERR_BAD_DB_PASSWORD;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (CMT_DoDecryptionRequest(msg) != CMTSuccess) { rv = PR_FAILURE; goto loser; }
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
SSMStatus
|
||||
SSMControlConnection_ProcessMiscRequest(SSMControlConnection * ctrl,
|
||||
|
@ -166,6 +210,26 @@ SSMControlConnection_ProcessMiscRequest(SSMControlConnection * ctrl,
|
|||
msg->type = (SECItemType) (SSM_REPLY_OK_MESSAGE | SSM_MISC_ACTION | SSM_MISC_GET_RNG_DATA);
|
||||
goto done;
|
||||
|
||||
case SSM_MISC_SDR_ENCRYPT:
|
||||
/*
|
||||
PK11_Authenticate(PK11_GetInternalKeySlot(), PR_TRUE, ctrl);
|
||||
|
||||
if (CMT_DoEncryptionRequest(msg) != CMTSuccess) goto loser;
|
||||
*/
|
||||
rv = SSM_ProcessMsgOnThread(sdrencrypt, ctrl, msg);
|
||||
if (rv != PR_SUCCESS) goto loser;
|
||||
|
||||
rv = SSM_ERR_DEFER_RESPONSE;
|
||||
goto done;
|
||||
|
||||
case SSM_MISC_SDR_DECRYPT:
|
||||
rv = SSM_ProcessMsgOnThread(sdrdecrypt, ctrl, msg);
|
||||
if (rv != PR_SUCCESS) goto loser;
|
||||
|
||||
rv = SSM_ERR_DEFER_RESPONSE;
|
||||
|
||||
goto done;
|
||||
|
||||
case SSM_MISC_PUT_RNG_DATA:
|
||||
default:
|
||||
SSM_DEBUG("Unknown misc request (%lx).\n", (msg->type & SSM_SUBTYPE_MASK));
|
||||
|
|
Загрузка…
Ссылка в новой задаче