зеркало из https://github.com/mozilla/pjs.git
First checkin of PSM client libs
This commit is contained in:
Родитель
94d79fc3ba
Коммит
f5584c7f65
|
@ -0,0 +1,45 @@
|
|||
#! gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = protocol client
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
#! gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = cmt
|
||||
|
||||
EXPORTS = \
|
||||
cmtcmn.h \
|
||||
cmtjs.h \
|
||||
cmtclist.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
|
||||
CSRCS = cmtinit.c \
|
||||
cmtssl.c \
|
||||
cmtutils.c \
|
||||
cmtcert.c \
|
||||
cmthash.c \
|
||||
cmtpkcs7.c \
|
||||
cmtres.c \
|
||||
cmtjs.c \
|
||||
cmtevent.c \
|
||||
cmtpasswd.c \
|
||||
cmtadvisor.c \
|
||||
cmtrng.c \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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 "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "obscure.h"
|
||||
#include "messages.h"
|
||||
#ifdef XP_MAC
|
||||
#include "cmtmac.h"
|
||||
#endif
|
||||
|
||||
CMTStatus CMT_SecurityAdvisor(PCMT_CONTROL control, CMTSecurityAdvisorData* data, CMUint32 *resID)
|
||||
{
|
||||
CMTItem message = {0, NULL, 0};
|
||||
SecurityAdvisorRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.infoContext = data->infoContext;
|
||||
request.resID = data->resID;
|
||||
request.hostname = data->hostname;
|
||||
request.senderAddr = data->senderAddr;
|
||||
request.encryptedP7CInfo = data->encryptedP7CInfo;
|
||||
request.signedP7CInfo = data->signedP7CInfo;
|
||||
request.decodeError = data->decodeError;
|
||||
request.verifyError = data->verifyError;
|
||||
request.encryptthis = data->encryptthis;
|
||||
request.signthis = data->signthis;
|
||||
request.numRecipients = data->numRecipients;
|
||||
request.recipients = data->recipients;
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_SECURITY_ADVISOR;
|
||||
|
||||
if (CMT_EncodeMessage(SecurityAdvisorRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SECURITY_ADVISOR)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*resID = reply.value;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
|
||||
if (message.data) {
|
||||
free(message.data);
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,461 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include <string.h>
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/* Typedefs */
|
||||
typedef void (*taskcompleted_handler_fn)(CMUint32 resourceID, CMUint32 numReqProcessed, CMUint32 resultCode, void* data);
|
||||
|
||||
CMTStatus CMT_SetUIHandlerCallback(PCMT_CONTROL control,
|
||||
uiHandlerCallback_fn f, void *data)
|
||||
{
|
||||
return CMT_RegisterEventHandler(control, SSM_UI_EVENT, 0,
|
||||
(void_fun)f, data);
|
||||
}
|
||||
|
||||
void CMT_SetFilePathPromptCallback(PCMT_CONTROL control,
|
||||
filePathPromptCallback_fn f, void* arg)
|
||||
{
|
||||
control->userFuncs.promptFilePath = f;
|
||||
control->userFuncs.filePromptArg = arg;
|
||||
}
|
||||
|
||||
void CMT_SetPromptCallback(PCMT_CONTROL control,
|
||||
promptCallback_fn f, void *arg)
|
||||
{
|
||||
control->userFuncs.promptCallback = f;
|
||||
control->userFuncs.promptArg = arg;
|
||||
}
|
||||
|
||||
void CMT_SetSavePrefsCallback(PCMT_CONTROL control, savePrefsCallback_fn f)
|
||||
{
|
||||
control->userFuncs.savePrefs = f;
|
||||
}
|
||||
|
||||
CMTStatus CMT_RegisterEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID, void_fun handler,
|
||||
void* data)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
/* This is the first connection */
|
||||
if (control->cmtEventHandlers == NULL) {
|
||||
control->cmtEventHandlers = ptr =
|
||||
(PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (!ptr) {
|
||||
goto loser;
|
||||
}
|
||||
} else {
|
||||
/* Look for another event handler of the same type. Make sure the
|
||||
event handler with a rsrcid of 0 is farther down the list so
|
||||
that it doesn't get chosen when there's an event handler for
|
||||
a specific rsrcid.
|
||||
*/
|
||||
for (ptr=control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->type == type && resourceID != 0) {
|
||||
/* So we've got an event handler that wants to over-ride
|
||||
an existing event handler. We'll put it before the one
|
||||
that's already here.
|
||||
*/
|
||||
if (ptr->previous == NULL) {
|
||||
/* We're going to insert at the front of the list*/
|
||||
control->cmtEventHandlers = ptr->previous =
|
||||
(PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (ptr->previous == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
ptr->previous->next = ptr;
|
||||
ptr = control->cmtEventHandlers;
|
||||
} else {
|
||||
/* We want to insert in the middle of the list */
|
||||
PCMT_EVENT tmpEvent;
|
||||
|
||||
tmpEvent = (PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (tmpEvent == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
tmpEvent->previous = ptr->previous;
|
||||
ptr->previous->next = tmpEvent;
|
||||
tmpEvent->next = ptr;
|
||||
ptr->previous = tmpEvent;
|
||||
ptr = tmpEvent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ptr->next == NULL) break;
|
||||
}
|
||||
if (ptr == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (ptr->next == NULL) {
|
||||
/* We're adding the event handler at the end of the list. */
|
||||
ptr->next = (PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (!ptr->next) {
|
||||
goto loser;
|
||||
}
|
||||
/* Fix up the pointers */
|
||||
ptr->next->previous = ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill in the data */
|
||||
ptr->type = type;
|
||||
ptr->resourceID = resourceID;
|
||||
ptr->handler = handler;
|
||||
ptr->data = data;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_UnregisterEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr, pptr = NULL;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL;
|
||||
pptr = ptr, ptr = ptr->next) {
|
||||
if ((ptr->type == type) && (ptr->resourceID == resourceID)) {
|
||||
if (pptr == NULL) {
|
||||
/* node is at head */
|
||||
control->cmtEventHandlers = ptr->next;
|
||||
if (control->cmtEventHandlers != NULL) {
|
||||
control->cmtEventHandlers->previous = NULL;
|
||||
}
|
||||
free(ptr);
|
||||
return CMTSuccess;
|
||||
}
|
||||
/* node is elsewhere */
|
||||
pptr->next = ptr->next;
|
||||
if (ptr->next != NULL) {
|
||||
ptr->next->previous = pptr;
|
||||
}
|
||||
free(ptr);
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == type) && ((ptr->resourceID == resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetFirstEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == type) && ((ptr->resourceID == resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetNextEventHandler(PCMT_CONTROL control, PCMT_EVENT e)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL || ptr == e;
|
||||
ptr = ptr->next) {
|
||||
}
|
||||
|
||||
for (; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == e->type) && ((ptr->resourceID == e->resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_ProcessEvent(PCMT_CONTROL cm_control)
|
||||
{
|
||||
CMTSocket sock;
|
||||
CMTItem eventData={ 0 };
|
||||
|
||||
/* Get the control socket */
|
||||
sock = cm_control->sock;
|
||||
|
||||
/* Acquire a lock on the control connection */
|
||||
CMT_LOCK(cm_control->mutex);
|
||||
/* Do another select here to be sure
|
||||
that the socket is readable */
|
||||
if (cm_control->sockFuncs.select(&sock, 1, 1) != sock) {
|
||||
/* There's no event. */
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Read the event */
|
||||
if (CMT_ReceiveMessage(cm_control, &eventData) == CMTFailure) {
|
||||
goto done;
|
||||
}
|
||||
CMT_UNLOCK(cm_control->mutex);
|
||||
/* Dispatch the event */
|
||||
CMT_DispatchEvent(cm_control, &eventData);
|
||||
return;
|
||||
done:
|
||||
/* Release the lock on the control connection */
|
||||
CMT_UNLOCK(cm_control->mutex);
|
||||
}
|
||||
|
||||
void CMT_EventLoop(PCMT_CONTROL cm_control)
|
||||
{
|
||||
CMTSocket sock;
|
||||
|
||||
/* Get the control socket */
|
||||
sock = cm_control->sock;
|
||||
CMT_ReferenceControlConnection(cm_control);
|
||||
/* Select on the control socket to see if it's readable */
|
||||
while(cm_control->sockFuncs.select(&sock, 1, 0)) {
|
||||
CMT_ProcessEvent(cm_control);
|
||||
}
|
||||
CMT_CloseControlConnection(cm_control);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
CMT_PromptUser(PCMT_CONTROL cm_control, CMTItem *eventData)
|
||||
{
|
||||
char *promptReply = NULL;
|
||||
CMTItem response={ 0 };
|
||||
PromptRequest request;
|
||||
PromptReply reply;
|
||||
void * clientContext;
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(PromptRequestTemplate, &request, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(request.clientContext);
|
||||
|
||||
if (cm_control->userFuncs.promptCallback == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
promptReply =
|
||||
cm_control->userFuncs.promptCallback(cm_control->userFuncs.promptArg,
|
||||
request.prompt, clientContext, 1);
|
||||
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_PROMPT_EVENT;
|
||||
if (!promptReply) {
|
||||
/* the user canceled the prompt or other errors occurred */
|
||||
reply.cancel = CM_TRUE;
|
||||
}
|
||||
else {
|
||||
/* note that this includes an empty string (zero length) password */
|
||||
reply.cancel = CM_FALSE;
|
||||
}
|
||||
reply.resID = request.resID;
|
||||
reply.promptReply = promptReply;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(PromptReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
loser:
|
||||
if (promptReply != NULL) {
|
||||
cm_control->userFuncs.userFree(promptReply);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_GetFilePath(PCMT_CONTROL cm_control, CMTItem * eventData)
|
||||
{
|
||||
char *fileName=NULL;
|
||||
CMTItem response = { 0 };
|
||||
FilePathRequest request;
|
||||
FilePathReply reply;
|
||||
|
||||
/* Decode the request */
|
||||
if (CMT_DecodeMessage(FilePathRequestTemplate, &request, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (cm_control->userFuncs.promptFilePath == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
fileName =
|
||||
cm_control->userFuncs.promptFilePath(cm_control->userFuncs.filePromptArg,
|
||||
request.prompt, request.fileRegEx,
|
||||
request.getExistingFile);
|
||||
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_FILE_PATH_EVENT;
|
||||
reply.resID = request.resID;
|
||||
reply.filePath = fileName;
|
||||
|
||||
/* Encode the reply */
|
||||
if (CMT_EncodeMessage(FilePathReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
cm_control->userFuncs.userFree(fileName);
|
||||
loser:
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_SavePrefs(PCMT_CONTROL cm_control, CMTItem* eventData)
|
||||
{
|
||||
SetPrefListMessage request;
|
||||
int i;
|
||||
|
||||
/* decode the request */
|
||||
if (CMT_DecodeMessage(SetPrefListMessageTemplate, &request, eventData) !=
|
||||
CMTSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cm_control->userFuncs.savePrefs == NULL) {
|
||||
/* callback was not registered: bail */
|
||||
return;
|
||||
}
|
||||
cm_control->userFuncs.savePrefs(request.length,
|
||||
(CMTSetPrefElement*)request.list);
|
||||
|
||||
for (i = 0; i < request.length; i++) {
|
||||
if (request.list[i].key != NULL) {
|
||||
free(request.list[i].key);
|
||||
}
|
||||
if (request.list[i].value != NULL) {
|
||||
free(request.list[i].value);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData)
|
||||
{
|
||||
CMUint32 eventType;
|
||||
|
||||
/* Get the event type */
|
||||
if ((eventData->type & SSM_CATEGORY_MASK) != SSM_EVENT_MESSAGE) {
|
||||
/* Somehow there was a message on the socket that was not
|
||||
* an event message. Dropping it on the floor.
|
||||
*/
|
||||
goto loser;
|
||||
}
|
||||
eventType = (eventData->type & SSM_TYPE_MASK);
|
||||
|
||||
/* We must now dispatch the event based on it's type */
|
||||
switch (eventType) {
|
||||
case SSM_UI_EVENT:
|
||||
{
|
||||
PCMT_EVENT p;
|
||||
UIEvent event;
|
||||
void * clientContext = NULL;
|
||||
|
||||
/* Get the event data first */
|
||||
if (CMT_DecodeMessage(UIEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Convert the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(event.clientContext);
|
||||
|
||||
/* Call any handlers for this event */
|
||||
p = CMT_GetEventHandler(cm_control, eventType, event.resourceID);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
(*(uiHandlerCallback_fn)(p->handler))(event.resourceID,
|
||||
clientContext, event.width,
|
||||
event.height, event.url,
|
||||
p->data);
|
||||
break;
|
||||
}
|
||||
|
||||
case SSM_TASK_COMPLETED_EVENT:
|
||||
{
|
||||
PCMT_EVENT p;
|
||||
TaskCompletedEvent event;
|
||||
|
||||
/* Get the event data */
|
||||
if (CMT_DecodeMessage(TaskCompletedEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Call handler for this event */
|
||||
p = CMT_GetEventHandler(cm_control, eventType, event.resourceID);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
(*(taskcompleted_handler_fn)(p->handler))(event.resourceID,
|
||||
event.numTasks,
|
||||
event.result, p->data);
|
||||
break;
|
||||
}
|
||||
case SSM_AUTH_EVENT:
|
||||
CMT_ServicePasswordRequest(cm_control, eventData);
|
||||
break;
|
||||
case SSM_FILE_PATH_EVENT:
|
||||
CMT_GetFilePath(cm_control, eventData);
|
||||
break;
|
||||
case SSM_PROMPT_EVENT:
|
||||
CMT_PromptUser(cm_control, eventData);
|
||||
break;
|
||||
case SSM_SAVE_PREF_EVENT:
|
||||
CMT_SavePrefs(cm_control, eventData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
loser:
|
||||
free(eventData->data);
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#include "string.h"
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
CMTStatus CMT_HashCreate(PCMT_CONTROL control, CMUint32 algID,
|
||||
CMUint32 * connID)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = algID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_HASH_STREAM;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the response */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_HASH_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if(sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
/* Send the hello message */
|
||||
control->sockFuncs.send(sock, control->nonce.data, control->nonce.len);
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the connection ID */
|
||||
*connID = reply.connID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
*connID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Destroy(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the cotext implementation data */
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Begin(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Update(PCMT_CONTROL control, CMUint32 connectionID, const unsigned char * buf, CMUint32 len)
|
||||
{
|
||||
CMTSocket sock;
|
||||
CMUint32 sent;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_End(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
unsigned char * result, CMUint32 * resultlen,
|
||||
CMUint32 maxLen)
|
||||
{
|
||||
CMTItem hash = { 0 };
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !result || !resultlen) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Close the connection */
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the context info */
|
||||
if (CMT_GetStringAttribute(control, connectionID, SSM_FID_HASHCONN_RESULT,
|
||||
&hash) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
if (!hash.data) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*resultlen = hash.len;
|
||||
if (hash.len > maxLen) {
|
||||
memcpy(result, hash.data, maxLen);
|
||||
} else {
|
||||
memcpy(result, hash.data, hash.len);
|
||||
}
|
||||
|
||||
if (hash.data) {
|
||||
free(hash.data);
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (hash.data) {
|
||||
free(hash.data);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
|
@ -0,0 +1,576 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/tcp.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#include <direct.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "messages.h"
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "obscure.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define DIRECTORY_SEPARATOR '/'
|
||||
#elif defined WIN32
|
||||
#define DIRECTORY_SEPARATOR '\\'
|
||||
#elif defined XP_MAC
|
||||
#define DIRECTORY_SEPARATOR ':'
|
||||
#endif
|
||||
|
||||
/* Local defines */
|
||||
#define CARTMAN_PORT 11111
|
||||
#define MAX_PATH_LEN 256
|
||||
|
||||
/* write to the cmnav.log */
|
||||
#if 0
|
||||
#define LOG(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, x); fclose(f); } } while(0);
|
||||
#define LOG_S(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, "%s", x); fclose(f); } } while(0);
|
||||
#define ASSERT(x); if (!(x)) { LOG("ASSERT:"); LOG(#x); LOG("\n"); exit(-1); }
|
||||
#else
|
||||
#define LOG(x); ;
|
||||
#define LOG_S(x); ;
|
||||
#define ASSERT(x); ;
|
||||
#endif
|
||||
|
||||
/* On error, returns -1.
|
||||
** On success, returns non-negative number of unobscured bytes in buf
|
||||
*/
|
||||
int
|
||||
RecvInitObscureData(CMT_SocketFuncs *sockFuncs, CMTSocket sock,
|
||||
SSMObscureObject * obj, void * buf, int bufSize )
|
||||
{
|
||||
SSMObscureBool done = 0;
|
||||
int rv = -1;
|
||||
|
||||
do {
|
||||
int cc;
|
||||
cc = sockFuncs->recv(sock, buf, bufSize);
|
||||
if (cc <= 0)
|
||||
return -1;
|
||||
rv = SSMObscure_RecvInit(obj, buf, cc, &done);
|
||||
} while (!done);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* returns -1 on error, 0 on success. */
|
||||
int
|
||||
SendInitObscureData(CMT_SocketFuncs *sockFuncs, CMTSocket sock,
|
||||
SSMObscureObject * obj)
|
||||
{
|
||||
unsigned char * initBuf = NULL;
|
||||
int rv = -1;
|
||||
|
||||
do {
|
||||
int bufLen;
|
||||
int len;
|
||||
int cc;
|
||||
|
||||
bufLen = SSMObscure_SendInit(obj, NULL);
|
||||
if (bufLen <= 0)
|
||||
break;
|
||||
|
||||
initBuf = (unsigned char *) malloc(bufLen);
|
||||
if (!initBuf)
|
||||
break;
|
||||
|
||||
len = SSMObscure_SendInit(obj, initBuf);
|
||||
if (len != bufLen)
|
||||
break;
|
||||
|
||||
cc = sockFuncs->send(sock, initBuf, len);
|
||||
|
||||
/* Note, this code assumes a blocking socket,
|
||||
** and hence doesn't deal with short writes.
|
||||
*/
|
||||
if (cc < len)
|
||||
break;
|
||||
|
||||
rv = 0;
|
||||
|
||||
} while (0);
|
||||
|
||||
if (initBuf) {
|
||||
free(initBuf);
|
||||
initBuf = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
SSMObscureObject * InitClientObscureObject(CMT_SocketFuncs *sockFuncs,
|
||||
CMTSocket sock)
|
||||
{
|
||||
SSMObscureObject * sobj = NULL;
|
||||
unsigned char buf[512];
|
||||
int rv = -1;
|
||||
|
||||
/* Create the obscuring object */
|
||||
sobj = SSMObscure_Create(0);
|
||||
if (!sobj) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the initialization data */
|
||||
rv = SendInitObscureData(sockFuncs, sock, sobj);
|
||||
if (rv < 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Receive the obscuring initialization data */
|
||||
rv = RecvInitObscureData(sockFuncs, sock, sobj, buf, sizeof(buf));
|
||||
if (rv < 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return sobj;
|
||||
loser:
|
||||
if (sobj) {
|
||||
SSMObscure_Destroy(sobj);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
getCurrWorkDir(char *buf, int maxLen)
|
||||
{
|
||||
#if defined WIN32
|
||||
return _getcwd(buf, maxLen);
|
||||
#elif defined XP_UNIX
|
||||
return getcwd(buf, maxLen);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
setWorkingDir(char *path)
|
||||
{
|
||||
#if defined WIN32
|
||||
_chdir(path);
|
||||
#elif defined XP_UNIX
|
||||
chdir(path);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
launch_psm(char *executable)
|
||||
{
|
||||
char command[MAX_PATH_LEN];
|
||||
#ifdef WIN32
|
||||
STARTUPINFO sui;
|
||||
PROCESS_INFORMATION pi;
|
||||
UNALIGNED long *posfhnd;
|
||||
int i;
|
||||
char *posfile;
|
||||
|
||||
sprintf(command,"%s > psmlog", executable);
|
||||
ZeroMemory( &sui, sizeof(sui) );
|
||||
sui.cb = sizeof(sui);
|
||||
sui.cbReserved2 = (WORD)(sizeof( int ) + (3 * (sizeof( char ) +
|
||||
sizeof( long ))));
|
||||
sui.lpReserved2 = calloc( sui.cbReserved2, 1 );
|
||||
*((UNALIGNED int *)(sui.lpReserved2)) = 3;
|
||||
posfile = (char *)(sui.lpReserved2 + sizeof( int ));
|
||||
posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) +
|
||||
(3 * sizeof( char )));
|
||||
|
||||
for ( i = 0, posfile = (char *)(sui.lpReserved2 + sizeof( int )),
|
||||
posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) + (3 * sizeof( char ))) ;
|
||||
i < 3 ; i++, posfile++, posfhnd++ ) {
|
||||
|
||||
*posfile = 0;
|
||||
*posfhnd = (long)INVALID_HANDLE_VALUE;
|
||||
}
|
||||
/* Now, fire up PSM */
|
||||
if (!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS,
|
||||
NULL, NULL, &sui, &pi)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
#elif defined XP_UNIX
|
||||
sprintf(command,"./%s &", executable);
|
||||
if (system(command) == -1) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
#else
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
|
||||
PCMT_CONTROL CMT_EstablishControlConnection(char *inPath,
|
||||
CMT_SocketFuncs *sockFuncs,
|
||||
CMT_MUTEX *mutex)
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
char *executable;
|
||||
char *newWorkingDir;
|
||||
char oldWorkingDir[MAX_PATH_LEN];
|
||||
int i;
|
||||
char *path;
|
||||
size_t stringLen;
|
||||
struct stat stbuf;
|
||||
|
||||
/*
|
||||
* Create our own copy of path.
|
||||
* I'd like to do a straight strdup here, but that caused problems
|
||||
* for https.
|
||||
*/
|
||||
stringLen = strlen(inPath);
|
||||
|
||||
path = (char*) malloc(stringLen+1);
|
||||
memcpy(path, inPath, stringLen);
|
||||
path[stringLen] = '\0';
|
||||
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
return control;
|
||||
}
|
||||
/*
|
||||
* We have to try to launch it now, so it better be a valid
|
||||
* path.
|
||||
*/
|
||||
if (stat(path, &stbuf) == -1) {
|
||||
goto loser;
|
||||
}
|
||||
/*
|
||||
* Now we have to parse the path and launch the psm server.
|
||||
*/
|
||||
executable = strrchr(path, DIRECTORY_SEPARATOR);
|
||||
if (executable != NULL) {
|
||||
*executable = '\0';
|
||||
executable ++;
|
||||
newWorkingDir = path;
|
||||
} else {
|
||||
executable = path;
|
||||
newWorkingDir = NULL;
|
||||
}
|
||||
if (getCurrWorkDir(oldWorkingDir, MAX_PATH_LEN) == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
setWorkingDir(newWorkingDir);
|
||||
if (launch_psm(executable) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
setWorkingDir(oldWorkingDir);
|
||||
/*
|
||||
* Now try to connect to the psm server. We will try to connect
|
||||
* a maximum of 30 times and then give up.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
for (i=0; i<30; i++) {
|
||||
Sleep(1000);
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#elif defined XP_UNIX
|
||||
i = 0;
|
||||
while (i<1000) {
|
||||
i += sleep(10);
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Figure out how to sleep for a while first
|
||||
*/
|
||||
for (i=0; i<30; i++) {
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control!= NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (control == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (path) {
|
||||
free (path);
|
||||
}
|
||||
return control;
|
||||
loser:
|
||||
if (control != NULL) {
|
||||
CMT_CloseControlConnection(control);
|
||||
}
|
||||
if (path) {
|
||||
free(path);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
PCMT_CONTROL CMT_ControlConnect(CMT_MUTEX *mutex, CMT_SocketFuncs *sockFuncs)
|
||||
{
|
||||
PCMT_CONTROL control = NULL;
|
||||
CMTSocket sock=NULL;
|
||||
SSMObscureObject * obscureObj = NULL;
|
||||
#ifdef XP_UNIX
|
||||
int unixSock = 1;
|
||||
char path[20];
|
||||
#else
|
||||
int unixSock = 0;
|
||||
char *path=NULL;
|
||||
#endif
|
||||
|
||||
if (sockFuncs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef XP_UNIX
|
||||
sprintf(path, "/tmp/.nsmc-%d", (int)geteuid());
|
||||
#endif
|
||||
|
||||
sock = sockFuncs->socket(unixSock);
|
||||
if (sock == NULL) {
|
||||
LOG("Could not create a socket to connect to Control Connection.\n");
|
||||
goto loser;
|
||||
}
|
||||
/* Connect to the psm process */
|
||||
if (sockFuncs->connect(sock, CARTMAN_PORT, path)) {
|
||||
LOG("Could not connect to Cartman\n");
|
||||
goto loser;
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (sockFuncs->verify(sock) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG("Connected to Cartman\n");
|
||||
|
||||
/* Set up the protocol obfuscation */
|
||||
if (!(obscureObj = InitClientObscureObject(sockFuncs, sock))) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* fill in the CMTControl struct */
|
||||
control = (PCMT_CONTROL)calloc(sizeof(CMT_CONTROL), 1);
|
||||
if (control == NULL ) {
|
||||
goto loser;
|
||||
}
|
||||
control->sock = sock;
|
||||
control->obscureObj = obscureObj;
|
||||
if (mutex != NULL) {
|
||||
control->mutex = (CMT_MUTEX*)calloc(sizeof(CMT_MUTEX),1);
|
||||
if (control->mutex == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
*control->mutex = *mutex;
|
||||
}
|
||||
memcpy(&control->sockFuncs, sockFuncs, sizeof(CMT_SocketFuncs));
|
||||
control->refCount = 1;
|
||||
goto done;
|
||||
|
||||
loser:
|
||||
if (control != NULL) {
|
||||
free(control);
|
||||
}
|
||||
if (sock != NULL) {
|
||||
sockFuncs->close(sock);
|
||||
}
|
||||
control = NULL;
|
||||
|
||||
done:
|
||||
return control;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CloseControlConnection(PCMT_CONTROL control)
|
||||
{
|
||||
/* XXX Don't know what to do here yet */
|
||||
if (control != NULL) {
|
||||
CMInt32 refCount;
|
||||
CMT_LOCK(control->mutex);
|
||||
control->refCount--;
|
||||
refCount = control->refCount;
|
||||
CMT_UNLOCK(control->mutex);
|
||||
if (refCount <= 0) {
|
||||
if (control->mutex != NULL) {
|
||||
free (control->mutex);
|
||||
}
|
||||
if (control->obscureObj) {
|
||||
SSMObscure_Destroy(control->obscureObj);
|
||||
}
|
||||
control->sockFuncs.close(control->sock);
|
||||
free(control);
|
||||
}
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_Hello(PCMT_CONTROL control, CMUint32 version, char* profile,
|
||||
char* profileDir)
|
||||
{
|
||||
CMTItem message;
|
||||
PCMT_EVENT eventHandler;
|
||||
CMBool doesUI;
|
||||
HelloRequest request;
|
||||
HelloReply reply;
|
||||
|
||||
/* Check the passed parameters */
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
if (!profile) {
|
||||
return CMTFailure;
|
||||
}
|
||||
if (!profileDir) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* Create the hello message */
|
||||
eventHandler = CMT_GetEventHandler(control, SSM_UI_EVENT, 0);
|
||||
doesUI = (eventHandler == NULL) ? CM_FALSE : CM_TRUE;
|
||||
|
||||
/* Setup the request struct */
|
||||
request.version = version;
|
||||
request.policy = 0; /* no more policy */
|
||||
request.doesUI = doesUI;
|
||||
request.profile = profile;
|
||||
request.profileDir = profileDir;
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_HELLO_MESSAGE;
|
||||
|
||||
if (CMT_EncodeMessage(HelloRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_HELLO_MESSAGE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(HelloReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Successful response */
|
||||
if (reply.result == 0) {
|
||||
/* Save the nonce value */
|
||||
control->sessionID = reply.sessionID;
|
||||
control->protocolVersion = reply.version;
|
||||
control->port = reply.httpPort;
|
||||
control->nonce = reply.nonce;
|
||||
control->policy = reply.policy;
|
||||
control->serverStringVersion = reply.stringVersion;
|
||||
|
||||
/* XXX Free the messages */
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
/* XXX Free the messages */
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PassAllPrefs(PCMT_CONTROL control, int num,
|
||||
CMTSetPrefElement* list)
|
||||
{
|
||||
SetPrefListMessage request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
|
||||
if ((control == NULL) || (list == NULL)) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* pack the request */
|
||||
request.length = num;
|
||||
request.list = (SetPrefElement*)list;
|
||||
|
||||
if (CMT_EncodeMessage(SetPrefListMessageTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PREF_ACTION;
|
||||
|
||||
/* send the message */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PREF_ACTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* don't really need to check the return value */
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
char* CMT_GetServerStringVersion(PCMT_CONTROL control)
|
||||
{
|
||||
if (control == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return control->serverStringVersion;
|
||||
}
|
|
@ -0,0 +1,626 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
typedef struct _CMTP7Private {
|
||||
CMTPrivate priv;
|
||||
CMTP7ContentCallback cb;
|
||||
void *cb_arg;
|
||||
} CMTP7Private;
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderStart(PCMT_CONTROL control, void* clientContext, CMUint32 * connectionID, CMInt32 * result,
|
||||
CMTP7ContentCallback cb, void *cb_arg)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMTP7Private *priv=NULL;
|
||||
SingleItemMessage request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.item = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode message */
|
||||
if (CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7DECODE_STREAM;
|
||||
|
||||
/* Send the message. */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7DECODE_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
priv = (CMTP7Private *)malloc(sizeof(CMTP7Private));
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
priv->priv.dest = (CMTReclaimFunc) free;
|
||||
priv->cb = cb;
|
||||
priv->cb_arg = cb_arg;
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if (sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.send(sock, control->nonce.data,
|
||||
control->nonce.len) != control->nonce.len){
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*connectionID = reply.connID;
|
||||
|
||||
rv = CMT_SetPrivate(control, reply.connID, &priv->priv);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
if (priv) {
|
||||
free(priv);
|
||||
}
|
||||
|
||||
*result = reply.result;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderUpdate(PCMT_CONTROL control, CMUint32 connectionID, const char * buf, CMUint32 len)
|
||||
{
|
||||
CMUint32 sent;
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char read_buf[128];
|
||||
CMTSocket sock, ctrlsock, selSock, sockArr[2];
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
while ((selSock = control->sockFuncs.select(sockArr,2,1)))
|
||||
{
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else {
|
||||
nbytes = control->sockFuncs.recv(sock, read_buf, sizeof(read_buf));
|
||||
if (nbytes == -1) {
|
||||
goto loser;
|
||||
}
|
||||
if (nbytes == 0) {
|
||||
break;
|
||||
}
|
||||
priv->cb(priv->cb_arg, read_buf, nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderFinish(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMUint32 * resourceID)
|
||||
{
|
||||
CMTP7Private *priv;
|
||||
long nbytes;
|
||||
char buf[128];
|
||||
CMTSocket sock, ctrlsock, selSock, sockArr[2];
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
/* drain socket before we close it */
|
||||
control->sockFuncs.shutdown(sock);
|
||||
sockArr[0] = sock;
|
||||
sockArr[1] = ctrlsock;
|
||||
while (1) {
|
||||
selSock = control->sockFuncs.select(sockArr,2,0);
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else if (selSock == sock) {
|
||||
nbytes = control->sockFuncs.recv(sock, buf, sizeof(buf));
|
||||
if (nbytes < 0) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
}
|
||||
priv->cb(priv->cb_arg, buf, nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the PKCS7 content info */
|
||||
if (CMT_GetRIDAttribute(control, connectionID, SSM_FID_P7CONN_CONTENT_INFO,
|
||||
resourceID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control) {
|
||||
CMT_CloseDataConnection(control, connectionID);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DestroyContentInfo(PCMT_CONTROL control, CMUint32 resourceID)
|
||||
{
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Delete the resource */
|
||||
if (CMT_DestroyResource(control, resourceID, SSM_FID_P7CONN_CONTENT_INFO) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7VerifyDetachedSignature(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 certUsage, CMUint32 hashAlgID, CMUint32 keepCerts, CMTItem* digest, CMInt32 * result)
|
||||
{
|
||||
CMTItem message;
|
||||
VerifyDetachedSigRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !digest || !result) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.pkcs7ContentID = resourceID;
|
||||
request.certUsage = certUsage;
|
||||
request.hashAlgID = hashAlgID;
|
||||
request.keepCert = (CMBool) keepCerts;
|
||||
request.hash = *digest;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(VerifyDetachedSigRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_VERIFY_DETACHED_SIG;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING |SSM_VERIFY_DETACHED_SIG)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*result = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
*result = reply.value;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7VerifySignature(PCMT_CONTROL control, CMUint32 pubKeyAlgID,
|
||||
CMTItem *pubKeyParams, CMTItem *signerPubKey,
|
||||
CMTItem *computedHash, CMTItem *signature,
|
||||
CMInt32 *result)
|
||||
{
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CreateSigned(PCMT_CONTROL control, CMUint32 scertRID,
|
||||
CMUint32 ecertRID, CMUint32 dig_alg,
|
||||
CMTItem *digest, CMUint32 *ciRID, CMInt32 *errCode)
|
||||
{
|
||||
CMTItem message;
|
||||
CreateSignedRequest request;
|
||||
CreateContentInfoReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !scertRID || !ecertRID || !digest || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.scertRID = scertRID;
|
||||
request.ecertRID = ecertRID;
|
||||
request.dig_alg = dig_alg;
|
||||
request.digest = *digest;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateSignedRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ciRID = reply.ciRID;
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) == CMTSuccess) {
|
||||
*errCode = reply.errorCode;
|
||||
} else {
|
||||
*errCode = 0;
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CreateEncrypted(PCMT_CONTROL control, CMUint32 scertRID,
|
||||
CMUint32 *rcertRIDs, CMUint32 *ciRID)
|
||||
{
|
||||
CMTItem message;
|
||||
CMInt32 nrcerts;
|
||||
CreateEncryptedRequest request;
|
||||
CreateContentInfoReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !scertRID || !rcertRIDs || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Calculate the number of certs */
|
||||
for (nrcerts =0; rcertRIDs[nrcerts] != 0; nrcerts++) {
|
||||
/* Nothing */
|
||||
;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.scertRID = scertRID;
|
||||
request.nrcerts = nrcerts;
|
||||
request.rcertRIDs = (long *) rcertRIDs;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateEncryptedRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message response type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ciRID = reply.ciRID;
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderStart(PCMT_CONTROL control, CMUint32 ciRID,
|
||||
CMUint32 *connectionID, CMTP7ContentCallback cb,
|
||||
void *cb_arg)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMTP7Private *priv;
|
||||
PKCS7DataConnectionRequest request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = ciRID;
|
||||
request.clientContext.len = 0;
|
||||
request.clientContext.data = NULL;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(PKCS7DataConnectionRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
priv = (CMTP7Private *)malloc(sizeof(CMTP7Private));
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
priv->priv.dest = (CMTReclaimFunc) free;
|
||||
priv->cb = cb;
|
||||
priv->cb_arg = cb_arg;
|
||||
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if (sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
if (control->sockFuncs.send(sock, control->nonce.data,
|
||||
control->nonce.len) != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*connectionID = reply.connID;
|
||||
|
||||
rv = CMT_SetPrivate(control, reply.connID, &priv->priv);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderUpdate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
const char *buf, CMUint32 len)
|
||||
{
|
||||
CMUint32 sent;
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char read_buf[128];
|
||||
CMTSocket sock, ctrlsock, sockArr[2], selSock;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !connectionID || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
while ((selSock = control->sockFuncs.select(sockArr, 2, 1)) != NULL)
|
||||
{
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else {
|
||||
nbytes = control->sockFuncs.recv(sock, read_buf, sizeof(read_buf));
|
||||
if (nbytes == -1) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
} else {
|
||||
priv->cb(priv->cb_arg, read_buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderFinish(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char buf[128];
|
||||
CMTSocket sock, ctrlsock, sockArr[2], selSock;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
control->sockFuncs.shutdown(sock);
|
||||
while (1) {
|
||||
selSock = control->sockFuncs.select(sockArr, 2, 0);
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else if (selSock == sock) {
|
||||
nbytes = control->sockFuncs.recv(sock, buf, sizeof(buf));
|
||||
if (nbytes < 0) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
} else {
|
||||
priv->cb(priv->cb_arg, buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control) {
|
||||
CMT_CloseDataConnection(control, connectionID);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
|
@ -0,0 +1,479 @@
|
|||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include <string.h>
|
||||
|
||||
CMTStatus CMT_GetNumericAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMInt32 *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*value = reply.value.u.numeric;
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_SetNumericAttribute(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 fieldID, CMInt32 value)
|
||||
{
|
||||
CMTItem message;
|
||||
SetAttribRequest request;
|
||||
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
request.value.type = SSM_NUMERIC_ATTRIBUTE;
|
||||
request.value.u.numeric = value;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(SetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE;
|
||||
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_PadStringValue(CMTItem *dest, CMTItem src)
|
||||
{
|
||||
dest->data = NewArray(unsigned char, src.len+1);
|
||||
if (dest->data == NULL) {
|
||||
return CMTFailure;
|
||||
}
|
||||
memcpy(dest->data, src.data, src.len);
|
||||
dest->data[src.len] = '\0';
|
||||
dest->len = src.len;
|
||||
free(src.data);
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetStringAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMTItem *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_STRING_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_STRING_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the response */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
return CMT_PadStringValue(value, reply.value.u.string);
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SetStringAttribute(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 fieldID, CMTItem *value)
|
||||
{
|
||||
CMTItem message;
|
||||
SetAttribRequest request;
|
||||
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
request.value.type = SSM_STRING_ATTRIBUTE;
|
||||
request.value.u.string = *value;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_STRING_ATTRIBUTE;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message request type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_STRING_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_DuplicateResource(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 *newResID)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
DupResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = resourceID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_DUPLICATE_RESOURCE;
|
||||
|
||||
/* Send the mesage */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_DUPLICATE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DupResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*newResID = reply.resID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
*newResID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_DestroyResource(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 resourceType)
|
||||
{
|
||||
CMTItem message;
|
||||
DestroyResourceRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.resType = resourceType;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(DestroyResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_DESTROY_RESOURCE;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_DESTROY_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.value == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PickleResource(PCMT_CONTROL control, CMUint32 resourceID, CMTItem * pickledResource)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
PickleResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = resourceID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_PICKLE_RESOURCE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_PICKLE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(PickleResourceReplyTemplate, &reply,&message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*pickledResource = reply.blob;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_UnpickleResource(PCMT_CONTROL control, CMUint32 resourceType, CMTItem pickledResource, CMUint32 * resourceID)
|
||||
{
|
||||
CMTItem message;
|
||||
UnpickleResourceRequest request;
|
||||
UnpickleResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resourceType = resourceType;
|
||||
request.resourceData = pickledResource;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(UnpickleResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_UNPICKLE_RESOURCE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_UNPICKLE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(UnpickleResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*resourceID = reply.resID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
*resourceID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetRIDAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMUint32 *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_RID_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message response type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_RID_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*value = reply.value.u.rid;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
|
@ -0,0 +1,467 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#else /* windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
|
||||
|
||||
CMTStatus CMT_OpenSSLConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
SSMSSLConnectionRequestType flags,
|
||||
CMUint32 port, char * hostIP,
|
||||
char * hostName, CMBool forceHandshake, void* clientContext)
|
||||
{
|
||||
CMTItem message;
|
||||
SSLDataConnectionRequest request;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.flags = flags;
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
request.forceHandshake = forceHandshake;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode message */
|
||||
if (CMT_EncodeMessage(SSLDataConnectionRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_SSL_CONNECTION;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_SSL_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLDataErrorCode(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMInt32* errorCode)
|
||||
{
|
||||
CMUint32 connID;
|
||||
|
||||
if (!control || !errorCode) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the PR error */
|
||||
if (CMT_GetNumericAttribute(control, connID, SSM_FID_SSLDATA_ERROR_VALUE,
|
||||
errorCode) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReleaseSSLSocketStatus(PCMT_CONTROL control, CMTSocket sock)
|
||||
{
|
||||
CMUint32 connectionID;
|
||||
|
||||
if (!control || !sock) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_SetNumericAttribute(control, connectionID,
|
||||
SSM_FID_SSLDATA_DISCARD_SOCKET_STATUS,
|
||||
0) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLSocketStatus(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMTItem* pickledStatus, CMInt32* level)
|
||||
{
|
||||
CMUint32 connectionID;
|
||||
SingleNumMessage request;
|
||||
CMTItem message;
|
||||
PickleSecurityStatusReply reply;
|
||||
|
||||
if (!control || !pickledStatus || !level) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.value = connectionID;
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_CONSERVE_RESOURCE | SSM_PICKLE_SECURITY_STATUS;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_CONSERVE_RESOURCE | SSM_PICKLE_SECURITY_STATUS)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(PickleSecurityStatusReplyTemplate, &reply, &message)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
*pickledStatus = reply.blob;
|
||||
*level = reply.securityLevel;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_OpenTLSConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 port, char* hostIP, char* hostName)
|
||||
{
|
||||
TLSDataConnectionRequest request;
|
||||
CMTItem message;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
|
||||
/* encode the message */
|
||||
if (CMT_EncodeMessage(TLSDataConnectionRequestTemplate, &message, &request)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_TLS_CONNECTION;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_TLS_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_TLSStepUp(PCMT_CONTROL control, CMTSocket sock,
|
||||
void* clientContext)
|
||||
{
|
||||
TLSStepUpRequest request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMUint32 connectionID;
|
||||
|
||||
/* check arguments */
|
||||
if (!control || !sock) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection ID */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.connID = connectionID;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(TLSStepUpRequestTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_TLS_STEPUP;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_TLS_STEPUP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_OpenSSLProxyConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 port, char* hostIP,
|
||||
char* hostName)
|
||||
{
|
||||
TLSDataConnectionRequest request;
|
||||
CMTItem message;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
|
||||
/* encode the message */
|
||||
if (CMT_EncodeMessage(TLSDataConnectionRequestTemplate, &message, &request)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_PROXY_CONNECTION;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_PROXY_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_ProxyStepUp(PCMT_CONTROL control, CMTSocket sock,
|
||||
void* clientContext, char* remoteUrl)
|
||||
{
|
||||
ProxyStepUpRequest request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMUint32 connectionID;
|
||||
|
||||
/* check arguments */
|
||||
if (!control || !sock || !remoteUrl) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection ID */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.connID = connectionID;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
request.url = remoteUrl;
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(ProxyStepUpRequestTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_PROXY_STEPUP;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_PROXY_STEPUP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
|
@ -0,0 +1,660 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "newproto.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Local defines */
|
||||
#if 0
|
||||
#define PSM_WAIT_BEFORE_SLEEP (CM_TicksPerSecond() * 60)
|
||||
#define PSM_SPINTIME PSM_WAIT_BEFORE_SLEEP
|
||||
#define PSM_KEEP_CONNECTION_ALIVE (PSM_WAIT_BEFORE_SLEEP * 900)
|
||||
#endif
|
||||
|
||||
/* If you want to dump the messages sent between the plug-in and the PSM
|
||||
* server, then remove the comment for the appropriate define.
|
||||
*/
|
||||
#if 0
|
||||
#define PRINT_SEND_MESSAGES
|
||||
#define PRINT_RECEIVE_MESSAGES
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_SEND_MESSAGES
|
||||
#ifndef DEBUG_MESSAGES
|
||||
#define DEBUG_MESSAGES
|
||||
#endif /*DEBUG_MESSAGES*/
|
||||
#endif /*PRINT_SEND_MESSAGES*/
|
||||
|
||||
#ifdef PRINT_RECEIVE_MESSAGES
|
||||
#ifndef DEBUG_MESSAGES
|
||||
#define DEBUG_MESSAGES
|
||||
#endif /*DEBUG_MESSAGES*/
|
||||
#endif /*PRINT_RECEIVE_MESSAGES*/
|
||||
|
||||
#ifdef DEBUG_MESSAGES
|
||||
#define LOG(x) do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, x); fclose(f); } } while(0);
|
||||
#define LOG_S(x) do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, "%s", x); fclose(f); } } while(0);
|
||||
#define ASSERT(x) if (!(x)) { LOG("ASSERT:"); LOG(#x); LOG("\n"); exit(-1); }
|
||||
#else
|
||||
#define LOG(x)
|
||||
#define LOG_S(x)
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
CMUint32
|
||||
cmt_Strlen(char *str)
|
||||
{
|
||||
CMUint32 len = strlen(str);
|
||||
return sizeof(CMInt32) + (((len + 3)/4)*4);
|
||||
}
|
||||
|
||||
CMUint32
|
||||
cmt_Bloblen(CMTItem *blob)
|
||||
{
|
||||
return sizeof(CMInt32) + (((blob->len +3)/4)*4);
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_PackString(char *buf, char *str)
|
||||
{
|
||||
CMUint32 len = strlen(str);
|
||||
CMUint32 networkLen = htonl(len);
|
||||
CMUint32 padlen = ((len + 3)/4)*4;
|
||||
|
||||
memcpy(buf, &networkLen, sizeof(CMUint32));
|
||||
memcpy(buf + sizeof(CMUint32), str, len);
|
||||
memset(buf + sizeof(CMUint32) + len, 0, padlen - len);
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_PackBlob(char *buf, CMTItem *blob)
|
||||
{
|
||||
CMUint32 len = blob->len;
|
||||
CMUint32 networkLen = htonl(len);
|
||||
CMUint32 padlen = (((blob->len + 3)/4)*4);
|
||||
|
||||
*((CMUint32*)buf) = networkLen;
|
||||
memcpy(buf + sizeof(CMUint32), blob->data, len);
|
||||
memset(buf + sizeof(CMUint32) + len, 0, padlen - len);
|
||||
|
||||
return buf + sizeof(CMUint32) + padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_UnpackString(char *buf, char **str)
|
||||
{
|
||||
char *p = NULL;
|
||||
CMUint32 len, padlen;
|
||||
|
||||
/* Get the string length */
|
||||
len = ntohl(*(CMUint32*)buf);
|
||||
|
||||
/* Get the padded length */
|
||||
padlen = ((len + 3)/4)*4;
|
||||
|
||||
/* Allocate the string and copy the data */
|
||||
p = (char *) malloc(len + 1);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
/* Copy the data and NULL terminate */
|
||||
memcpy(p, buf+sizeof(CMUint32), len);
|
||||
p[len] = 0;
|
||||
|
||||
*str = p;
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
loser:
|
||||
*str = NULL;
|
||||
if (p) {
|
||||
free(p);
|
||||
}
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_UnpackBlob(char *buf, CMTItem **blob)
|
||||
{
|
||||
CMTItem *p = NULL;
|
||||
CMUint32 len, padlen;
|
||||
|
||||
/* Get the blob length */
|
||||
len = ntohl(*(CMUint32*)buf);
|
||||
|
||||
/* Get the padded length */
|
||||
padlen = ((len + 3)/4)*4;
|
||||
|
||||
/* Allocate the CMTItem for the blob */
|
||||
p = (CMTItem*)malloc(sizeof(CMTItem));
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
p->len = len;
|
||||
p->data = (unsigned char *) malloc(len);
|
||||
if (!p->data) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy that data across */
|
||||
memcpy(p->data, buf+sizeof(CMUint32), len);
|
||||
*blob = p;
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
|
||||
loser:
|
||||
*blob = NULL;
|
||||
CMT_FreeMessage(p);
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MESSAGES
|
||||
void prettyPrintMessage(CMTItem *msg)
|
||||
{
|
||||
int numLines = ((msg->len+7)/8);
|
||||
char curBuffer[9], *cursor, string[2], hexVal[8];
|
||||
char hexArray[25];
|
||||
int i, j, numToCopy;
|
||||
|
||||
/*Try printing out 8 bytes at a time. */
|
||||
LOG("\n**********************************************************\n");
|
||||
LOG("About to pretty Print Message\n\n");
|
||||
curBuffer[9] = '\0';
|
||||
hexArray[24] = '\0';
|
||||
hexVal[2] = '\0';
|
||||
string[1] = '\0';
|
||||
LOG("Header Info\n");
|
||||
LOG("Message Type: ");
|
||||
sprintf(hexArray, "%lx\n", msg->type);
|
||||
LOG(hexArray);
|
||||
LOG("Message Length: ");
|
||||
sprintf (hexArray, "%ld\n\n", msg->len);
|
||||
LOG(hexArray);
|
||||
LOG("Body of Message\n");
|
||||
for (i=0, cursor=msg->data; i<numLines; i++, cursor+=8) {
|
||||
/* First copy over the buffer to our local array */
|
||||
numToCopy = ((msg->len - (unsigned int)((unsigned long)cursor-(unsigned long)msg->data)) < 8) ?
|
||||
msg->len - (unsigned int)((unsigned long)cursor-(unsigned long)msg->data) : 8;
|
||||
memcpy(curBuffer, cursor, 8);
|
||||
for (j=0;j<numToCopy;j++) {
|
||||
string[0] = curBuffer[j];
|
||||
if (isprint(curBuffer[j])) {
|
||||
string[0] = curBuffer[j];
|
||||
} else {
|
||||
string[0] = ' ';
|
||||
}
|
||||
LOG(string);
|
||||
}
|
||||
string[0] = ' ';
|
||||
for (;j<8;j++) {
|
||||
LOG(string);
|
||||
}
|
||||
LOG("\t");
|
||||
for (j=0; j<numToCopy; j++) {
|
||||
sprintf (hexVal,"%.2x", 0x0ff & (unsigned short)curBuffer[j]);
|
||||
LOG(hexVal);
|
||||
LOG(" ");
|
||||
}
|
||||
LOG("\n");
|
||||
}
|
||||
LOG("Done Pretty Printing Message\n");
|
||||
LOG("**********************************************************\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
CMTStatus CMT_SendMessage(PCMT_CONTROL control, CMTItem* message)
|
||||
{
|
||||
CMTStatus status;
|
||||
CMUint32 msgCategory;
|
||||
CMBool done = CM_FALSE;
|
||||
#ifdef PRINT_SEND_MESSAGES
|
||||
LOG("About to print message sent to PSM\n");
|
||||
prettyPrintMessage(message);
|
||||
#endif
|
||||
|
||||
/* Acquire lock on the control connection */
|
||||
CMT_LOCK(control->mutex);
|
||||
|
||||
/* Try to send pending random data */
|
||||
if (message->type != (SSM_REQUEST_MESSAGE | SSM_HELLO_MESSAGE))
|
||||
{
|
||||
/* If we've already said hello, then flush random data
|
||||
just before sending the request. */
|
||||
status = CMT_FlushPendingRandomData(control);
|
||||
if (status != CMTSuccess)
|
||||
goto loser;
|
||||
}
|
||||
|
||||
status = CMT_TransmitMessage(control, message);
|
||||
if (status != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* We have to deal with other types of data on the socket and */
|
||||
/* handle them accordingly */
|
||||
while (!done) {
|
||||
status = CMT_ReceiveMessage(control, message);
|
||||
if (status != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
msgCategory = (message->type & SSM_CATEGORY_MASK);
|
||||
switch (msgCategory) {
|
||||
case SSM_REPLY_OK_MESSAGE:
|
||||
done = CM_TRUE;
|
||||
break;
|
||||
case SSM_REPLY_ERR_MESSAGE:
|
||||
done = CM_TRUE;
|
||||
break;
|
||||
case SSM_EVENT_MESSAGE:
|
||||
CMT_DispatchEvent(control, message);
|
||||
break;
|
||||
/* XXX FIX THIS!!! For the moment I'm ignoring all other types */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Release the control connection lock */
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
/* Release the control connection lock */
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_TransmitMessage(PCMT_CONTROL control, CMTItem * message)
|
||||
{
|
||||
CMTMessageHeader header;
|
||||
CMUint32 sent, rv;
|
||||
|
||||
/* Set up the message header */
|
||||
header.type = htonl(message->type);
|
||||
header.len = htonl(message->len);
|
||||
|
||||
/* Obscure the message header */
|
||||
rv = SSMObscure_Send(control->obscureObj, &header, sizeof(CMTMessageHeader));
|
||||
if (rv != 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message header */
|
||||
sent = CMT_WriteThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (sent != sizeof(CMTMessageHeader)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Obscure the message body */
|
||||
rv = SSMObscure_Send(control->obscureObj, message->data, message->len);
|
||||
if (rv != 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message body */
|
||||
sent = CMT_WriteThisMany(control, control->sock, (void *)message->data,
|
||||
message->len);
|
||||
if (sent != message->len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Free the buffer */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReceiveMessage(PCMT_CONTROL control, CMTItem * response)
|
||||
{
|
||||
CMTMessageHeader header;
|
||||
CMUint32 read, rv;
|
||||
|
||||
/* Get the obscured message header */
|
||||
read = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (read != sizeof(CMTMessageHeader)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Unobscure the message header */
|
||||
rv = SSMObscure_Recv(control->obscureObj, &header, sizeof(CMTMessageHeader));
|
||||
if (rv != 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
response->type = ntohl(header.type);
|
||||
response->len = ntohl(header.len);
|
||||
response->data = (unsigned char *) malloc(response->len);
|
||||
if (response->data == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
read = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)(response->data), response->len);
|
||||
if (read != response->len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Unobscure the message body */
|
||||
rv = SSMObscure_Recv(control->obscureObj, response->data, response->len);
|
||||
if (rv != 0) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
#ifdef PRINT_RECEIVE_MESSAGES
|
||||
LOG("About to print message received from PSM.\n");
|
||||
prettyPrintMessage(response);
|
||||
#endif /*PRINT_RECEIVE_MESSAGES*/
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
if (response->data) {
|
||||
free(response->data);
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMUint32 CMT_ReadThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany)
|
||||
{
|
||||
CMUint32 total = 0;
|
||||
|
||||
while (total < thisMany) {
|
||||
int got;
|
||||
got = control->sockFuncs.recv(sock, (void*)((char*)buffer + total),
|
||||
thisMany-total);
|
||||
if (got < 0 ) {
|
||||
break;
|
||||
}
|
||||
total += got;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
CMUint32 CMT_WriteThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany)
|
||||
{
|
||||
CMUint32 total = 0;
|
||||
|
||||
while (total < thisMany) {
|
||||
CMUint32 got;
|
||||
got = control->sockFuncs.send(sock, (void*)((char*)buffer+total),
|
||||
thisMany-total);
|
||||
if (got < 0) {
|
||||
break;
|
||||
}
|
||||
total += got;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
CMTItem* CMT_ConstructMessage(CMUint32 type, CMUint32 length)
|
||||
{
|
||||
CMTItem * p;
|
||||
|
||||
p = (CMTItem*)malloc(sizeof(CMTItem));
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
p->type = type;
|
||||
p->len = length;
|
||||
p->data = (unsigned char *) malloc(length);
|
||||
if (!p->data) {
|
||||
goto loser;
|
||||
}
|
||||
return p;
|
||||
|
||||
loser:
|
||||
CMT_FreeMessage(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_FreeMessage(CMTItem * p)
|
||||
{
|
||||
if (p != NULL) {
|
||||
if (p->data != NULL) {
|
||||
free(p->data);
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
CMTStatus CMT_AddDataConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
/* This is the first connection */
|
||||
if (control->cmtDataConnections == NULL) {
|
||||
control->cmtDataConnections = ptr =
|
||||
(PCMT_DATA)calloc(sizeof(CMT_DATA), 1);
|
||||
if (!ptr) {
|
||||
goto loser;
|
||||
}
|
||||
} else {
|
||||
/* Position at the last entry */
|
||||
for (ptr = control->cmtDataConnections; (ptr != NULL && ptr->next
|
||||
!= NULL); ptr = ptr->next);
|
||||
ptr->next = (PCMT_DATA)calloc(sizeof(CMT_DATA), 1);
|
||||
if (!ptr->next) {
|
||||
goto loser;
|
||||
}
|
||||
/* Fix up the pointers */
|
||||
ptr->next->previous = ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
/* Fill in the data */
|
||||
ptr->sock = sock;
|
||||
ptr->connectionID = connectionID;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
int
|
||||
CMT_DestroyDataConnection(PCMT_CONTROL control, CMTSocket sock)
|
||||
{
|
||||
PCMT_DATA ptr, pptr = NULL;
|
||||
int rv=CMTSuccess;
|
||||
|
||||
control->sockFuncs.close(sock);
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL;
|
||||
pptr = ptr, ptr = ptr->next) {
|
||||
if (ptr->sock == sock) {
|
||||
if (pptr == NULL) {
|
||||
/* node is at head */
|
||||
control->cmtDataConnections = ptr->next;
|
||||
if (ptr->priv != NULL)
|
||||
ptr->priv->dest(ptr->priv);
|
||||
free(ptr);
|
||||
return rv;
|
||||
}
|
||||
/* node is elsewhere */
|
||||
pptr->next = ptr->next;
|
||||
if (ptr->priv != NULL)
|
||||
ptr->priv->dest(ptr->priv);
|
||||
free(ptr);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CloseDataConnection(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
/* PCMT_DATA ptr, pptr = NULL; */
|
||||
CMTSocket sock;
|
||||
/* int rv;*/
|
||||
|
||||
/* Get the socket for this connection */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Free data connection associated with this socket */
|
||||
if (CMT_DestroyDataConnection(control, sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetDataConnectionID(PCMT_CONTROL control, CMTSocket sock, CMUint32 * connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->sock == sock) {
|
||||
*connectionID = ptr->connectionID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetDataSocket(PCMT_CONTROL control, CMUint32 connectionID, CMTSocket * sock)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
*sock = ptr->sock;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_SetPrivate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMTPrivate *cmtpriv)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
ptr->priv = cmtpriv;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTPrivate *CMT_GetPrivate(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
return ptr->priv;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_FreeItem(CMTItem *p)
|
||||
{
|
||||
CMT_FreeMessage(p);
|
||||
}
|
||||
|
||||
CMTItem CMT_CopyPtrToItem(void* p)
|
||||
{
|
||||
CMTItem value = {0, NULL, 0};
|
||||
|
||||
if (!p) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value.len = sizeof(p);
|
||||
value.data = (unsigned char *) malloc(value.len);
|
||||
memcpy(value.data, &p, value.len);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void * CMT_CopyItemToPtr(CMTItem value)
|
||||
{
|
||||
void * p = NULL;
|
||||
|
||||
if (value.len == sizeof(void*)) {
|
||||
memcpy(&p, value.data, value.len);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReferenceControlConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_LOCK(control->mutex);
|
||||
control->refCount++;
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
void
|
||||
CMT_LockConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_LOCK(control->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
CMT_UnlockConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_UNLOCK(control->mutex);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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 __CMTUTILS_H__
|
||||
#define __CMTUTILS_H__
|
||||
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#define New(type) (type*)malloc(sizeof(type))
|
||||
#define NewArray(type, size) (type*)malloc(sizeof(type)*(size))
|
||||
|
||||
PCMT_EVENT CMT_GetEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID);
|
||||
|
||||
CMUint32 cmt_Strlen(char *str);
|
||||
char *cmt_PackString(char *buf, char *str);
|
||||
char *cmt_UnpackString(char *buf, char **str);
|
||||
|
||||
CMUint32 cmt_Bloblen(CMTItem* len);
|
||||
char *cmt_PackBlob(char *buf, CMTItem * blob);
|
||||
char *cmt_UnpackBlob(char *buf, CMTItem **blob);
|
||||
|
||||
CMTStatus CMT_SendMessage(PCMT_CONTROL control, CMTItem* message);
|
||||
CMTStatus CMT_TransmitMessage(PCMT_CONTROL control, CMTItem * message);
|
||||
CMTStatus CMT_ReceiveMessage(PCMT_CONTROL control, CMTItem * response);
|
||||
CMUint32 CMT_ReadThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany);
|
||||
CMUint32 CMT_WriteThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany);
|
||||
CMTItem* CMT_ConstructMessage(CMUint32 type, CMUint32 length);
|
||||
void CMT_FreeMessage(CMTItem * p);
|
||||
CMTStatus CMT_AddDataConnection(PCMT_CONTROL control, CMTSocket sock, CMUint32 connectionID);
|
||||
CMTStatus CMT_GetDataConnectionID(PCMT_CONTROL control, CMTSocket sock, CMUint32 * connectionID);
|
||||
CMTStatus CMT_GetDataSocket(PCMT_CONTROL control, CMUint32 connectionID, CMTSocket * socket);
|
||||
CMTStatus CMT_CloseDataConnection(PCMT_CONTROL control, CMUint32 connectionID);
|
||||
CMTStatus CMT_SetPrivate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMTPrivate *cmtpriv);
|
||||
CMTPrivate *CMT_GetPrivate(PCMT_CONTROL control, CMUint32 connectionID);
|
||||
void CMT_ServicePasswordRequest(PCMT_CONTROL cm_control, CMTItem * requestData);
|
||||
void CMT_ProcessEvent(PCMT_CONTROL cm_control);
|
||||
void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData);
|
||||
CMTItem CMT_CopyPtrToItem(void* p);
|
||||
void * CMT_CopyItemToPtr(CMTItem value);
|
||||
|
||||
#endif /* __CMTUTILS_H__ */
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
PROGRAM =
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
#//
|
||||
#// 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.
|
||||
#//
|
||||
IGNORE_MANIFEST=1
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Makefile to build the ssl library
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
!if "$(MOZ_BITS)" == "16"
|
||||
!ifndef MOZ_DEBUG
|
||||
OPTIMIZER=-Os -UDEBUG -DNDEBUG
|
||||
!endif
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
!ifndef MAKE_OBJ_TYPE
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBNAME=cmt
|
||||
PDBFILE=$(LIBNAME).pdb
|
||||
|
||||
LINCS = -I$(PUBLIC)\security \
|
||||
-I$(PUBLIC)\nspr \
|
||||
-I$(DEPTH)\include \
|
||||
-I..\include
|
||||
|
||||
!ifndef OS_CONFIG
|
||||
OS_CONFIG = WIN$(MOZ_BITS)
|
||||
!endif
|
||||
|
||||
LCFLAGS = -DEXPORT_VERSION -DLIB_BUILD
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\cmtinit.obj \
|
||||
.\$(OBJDIR)\cmtssl.obj \
|
||||
.\$(OBJDIR)\cmtutils.obj \
|
||||
.\$(OBJDIR)\cmtpkcs7.obj \
|
||||
.\$(OBJDIR)\cmthash.obj \
|
||||
.\$(OBJDIR)\cmtcert.obj \
|
||||
.\$(OBJDIR)\cmtres.obj \
|
||||
.\$(OBJDIR)\cmtjs.obj \
|
||||
.\$(OBJDIR)\cmtevent.obj \
|
||||
.\$(OBJDIR)\cmtpasswd.obj \
|
||||
.\$(OBJDIR)\cmtadvisor.obj \
|
||||
.\$(OBJDIR)\cmtrng.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBRARY=.\$(OBJDIR)\$(LIBNAME).lib
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// install headers
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
INSTALL_DIR=$(PUBLIC)\security
|
||||
INSTALL_FILE_LIST=cmtcmn.h cmtjs.h cmtclist.h
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
export:: INSTALL_FILES
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../../../..
|
||||
DEPTH = ../../../..
|
||||
|
||||
EXPORTS = \
|
||||
cmtcmn.h \
|
||||
cmtjs.h \
|
||||
cmtclist.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
|
||||
CSRCS = cmtinit.c \
|
||||
cmtssl.c \
|
||||
cmtutils.c \
|
||||
cmtcert.c \
|
||||
cmthash.c \
|
||||
cmtpkcs7.c \
|
||||
cmtres.c \
|
||||
cmtjs.c \
|
||||
cmtevent.c \
|
||||
cmtpasswd.c \
|
||||
cmtadvisor.c \
|
||||
cmtrng.c \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = nspr security
|
||||
|
||||
LIBRARY_NAME = cmt
|
||||
|
||||
INCLUDES += -I$(CORE_DEPTH)/include
|
|
@ -0,0 +1,128 @@
|
|||
#! gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
ifneq ($(OS_ARCH), WINNT)
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
# On linux, we link with libstdc++
|
||||
CPLUSPLUSRUNTIME = -L /usr/lib -lstdc++ -lm
|
||||
else
|
||||
# libC, presumably, is what we must link with elsewhere
|
||||
CPLUSPLUSRUNTIME = -lC -lm
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
ifeq ($(OS_RELEASE), 5.5.1)
|
||||
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
|
||||
endif
|
||||
ifeq ($(OS_RELEASE), 5.6)
|
||||
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
ifdef USE_PTHREADS
|
||||
# Replace OS_LIBS, because the order of libpthread, libdl, and libc are
|
||||
# very important. Otherwise you get horrible crashes.
|
||||
OS_LIBS = -lpthread -ldl -lc
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
LDFLAGS += /NODEFAULTLIB:library
|
||||
endif
|
||||
|
||||
EXTRA_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)cmt.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)protocol.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
EXTRA_LIBS += wsock32.lib \
|
||||
winmm.lib \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
link:
|
||||
if test -f $(PROGRAM); then \
|
||||
echo "rm $(PROGRAM)"; \
|
||||
rm $(PROGRAM); \
|
||||
fi; \
|
||||
gmake \
|
||||
|
||||
build_sample:
|
||||
ifneq ($(OS_ARCH),WINNT)
|
||||
cd $(CORE_DEPTH)/coreconf; gmake
|
||||
endif
|
||||
cd $(CORE_DEPTH)/security; gmake import; gmake export
|
||||
cd ../../protocol; gmake
|
||||
cd ..; gmake
|
||||
gmake
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(PROGRAM)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
LIBRARY =
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
CORE_DEPTH = ../../../../..
|
||||
|
||||
# MODULE public and private header directories are implicitly REQUIRED.
|
||||
MODULE = cmtsample
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
sample.c \
|
||||
appsock.c \
|
||||
$(NULL)
|
||||
INCLUDES += -I../../protocol -I..
|
||||
|
||||
# The MODULE is always implicitly required.
|
||||
# Listing it here in REQUIRES makes it appear twice in the cc command line.
|
||||
REQUIRES = security
|
||||
|
||||
PROGRAM = cmtsample
|
||||
|
|
@ -0,0 +1,346 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 "cmtcmn.h"
|
||||
#include "cmtjs.h"
|
||||
#include "appsock.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <netdb.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a simple program that tries to detect if the psm server is loaded.
|
||||
* If the server is not loaded, it will start it. The program will then
|
||||
* connect to the server and fetch an HTML page from an SSL server.
|
||||
*
|
||||
* NOTE: This sample program does not implement a mutex for the libraries.
|
||||
* If implementing a threaded application, then pass in a mutex structure
|
||||
* so that connections to the psm server happen in a thread safe manner.
|
||||
*/
|
||||
|
||||
#define NUM_CONNECT_TRIES 10
|
||||
#define READ_BUFFER_SIZE 1024
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage:\n"
|
||||
"\tcmtsample <secure site>\n\n"
|
||||
"This program will then echo the retrieved HTML to the screen\n");
|
||||
}
|
||||
|
||||
void
|
||||
errorMessage(int err,char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
fprintf (stderr, "cmtSample%s: ", (err) ? " error" : "");
|
||||
vfprintf (stderr, msg, args);
|
||||
fprintf (stderr, "\n");
|
||||
va_end(args);
|
||||
if (err) {
|
||||
exit (err);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define FILE_PATH_SEPARATOR '/'
|
||||
#elif defined (WIN32)
|
||||
#define FILE_PATH_SEPARATOR '\\'
|
||||
#else
|
||||
#error Tell me what the file path separator is.
|
||||
#endif
|
||||
|
||||
PCMT_CONTROL
|
||||
connect_to_psm(void)
|
||||
{
|
||||
PCMT_CONTROL control=NULL;
|
||||
char path[256], *tmp;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (getcwd(path,256) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#elif defined(WIN32)
|
||||
if (_getcwd(path,256) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
#error Teach me how to get the current working directory.
|
||||
#endif
|
||||
tmp = &path[strlen(path)];
|
||||
sprintf(tmp,"%c%s", FILE_PATH_SEPARATOR, "psm");
|
||||
return CMT_EstablishControlConnection(path, &socketFuncs, NULL);
|
||||
}
|
||||
|
||||
#define HTTPS_STRING "https://"
|
||||
|
||||
char*
|
||||
extract_host_from_url(char *url)
|
||||
{
|
||||
char *start, *end, *retString=NULL;
|
||||
|
||||
while(isspace(*url)) {
|
||||
url++;
|
||||
}
|
||||
url = strdup(url);
|
||||
start = strstr(url, HTTPS_STRING);
|
||||
if (start == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
start += strlen(HTTPS_STRING);
|
||||
/*
|
||||
* Figure out the end of the host name.
|
||||
*/
|
||||
end = strchr(start, ':');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
} else {
|
||||
end = strchr(start, '/');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
} else {
|
||||
end = strchr(start, ' ');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
retString = strdup(start);
|
||||
return retString;
|
||||
}
|
||||
|
||||
CMUint32
|
||||
get_port_from_url(char *url)
|
||||
{
|
||||
char *colon, *port;
|
||||
|
||||
url = strdup(url);
|
||||
colon = strrchr(url, ':');
|
||||
if (colon == NULL ||
|
||||
!isdigit(colon[1])) {
|
||||
/* Return the default SSL port. */
|
||||
free(url);
|
||||
return 443;
|
||||
}
|
||||
colon++;
|
||||
port = colon;
|
||||
while(isdigit(*colon))
|
||||
colon++;
|
||||
colon[1] = '\0';
|
||||
free(url);
|
||||
return (CMUint32)atol(port);
|
||||
}
|
||||
|
||||
char*
|
||||
extract_get_target(char *url)
|
||||
{
|
||||
char *slash;
|
||||
|
||||
slash = strstr(url, "//");
|
||||
slash += 2;
|
||||
slash = strchr(slash, '/');
|
||||
if (slash != NULL)
|
||||
return strdup (slash);
|
||||
else
|
||||
return strdup ("/");
|
||||
}
|
||||
|
||||
/*
|
||||
* We'll use this function for prompting for a password.
|
||||
*/
|
||||
char*
|
||||
passwordCallback(void *arg, char *prompt, void *cotext, int isPaswd)
|
||||
{
|
||||
char input[256];
|
||||
|
||||
printf(prompt);
|
||||
fgets(input, 256, stdin);
|
||||
|
||||
return strdup(input);
|
||||
}
|
||||
|
||||
void
|
||||
freeCallback(char *userInput)
|
||||
{
|
||||
free (userInput);
|
||||
}
|
||||
|
||||
#define NUM_PREFS 2
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
CMTSocket sock, selSock;
|
||||
char *hostname;
|
||||
struct hostent *host;
|
||||
char *ipAddress;
|
||||
char buffer[READ_BUFFER_SIZE];
|
||||
size_t bytesRead;
|
||||
struct sockaddr_in destAddr;
|
||||
char *getString;
|
||||
char requestString[256];
|
||||
char *profile;
|
||||
CMTSetPrefElement prefs[NUM_PREFS];
|
||||
char profileDir[256];
|
||||
|
||||
#ifdef WIN32
|
||||
WORD WSAVersion = 0x0101;
|
||||
WSADATA WSAData;
|
||||
|
||||
WSAStartup (WSAVersion, &WSAData);
|
||||
#endif
|
||||
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
errorMessage (0,"cmtsample v1.0");
|
||||
errorMessage (0,"Will try connecting to site %s", argv[1]);
|
||||
if (strstr(argv[1], "https://") == NULL) {
|
||||
errorMessage(2,"%s is not a secure site", argv[1]);
|
||||
}
|
||||
control = connect_to_psm();
|
||||
if (control == NULL) {
|
||||
errorMessage(3, "Could not connect to the psm server");
|
||||
}
|
||||
/*
|
||||
* Now we have to send the hello message.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
profile = strdup("default");
|
||||
sprintf(profileDir,"%s", "c:\\default");
|
||||
#elif defined (XP_UNIX)
|
||||
profile = getenv("LOGNAME");
|
||||
sprintf(profileDir, "%s/.netscape", getenv("HOME"));
|
||||
#else
|
||||
#error Teach me how to fill in the user profile.
|
||||
#endif
|
||||
if (CMT_Hello(control, PROTOCOL_VERSION,
|
||||
profile, profileDir) != CMTSuccess)
|
||||
{
|
||||
errorMessage(10, "Failed to send the Hello Message.");
|
||||
}
|
||||
CMT_SetPromptCallback(control, passwordCallback, NULL);
|
||||
CMT_SetAppFreeCallback(control, freeCallback);
|
||||
/*
|
||||
* Now pass along some preferences to psm. We'll pass hard coded
|
||||
* ones here, but apps should figure out a way to manage their user's
|
||||
* preferences.
|
||||
*/
|
||||
prefs[0].key = "security.enable_ssl2";
|
||||
prefs[0].value = "true";
|
||||
prefs[0].type = CMT_PREF_BOOL;
|
||||
prefs[1].key = "security.enable_ssl3";
|
||||
prefs[1].value = "true";
|
||||
prefs[1].type = CMT_PREF_BOOL;
|
||||
CMT_PassAllPrefs(control, NUM_PREFS, prefs);
|
||||
hostname = extract_host_from_url(argv[1]);
|
||||
host = gethostbyname(hostname);
|
||||
if (host == NULL) {
|
||||
errorMessage(11, "gethostbyname for %s failed", hostname);
|
||||
}
|
||||
if (host->h_length != 4) {
|
||||
errorMessage(4, "Site %s uses IV v6 socket. Not supported by psm.");
|
||||
}
|
||||
|
||||
/* Create the socket we will use to get the decrypted data back from
|
||||
* the psm server.
|
||||
*/
|
||||
sock = APP_GetSocket(0);
|
||||
if (sock == NULL) {
|
||||
errorMessage(5, "Could not create new socket for communication with "
|
||||
"the psm server.");
|
||||
}
|
||||
memcpy(&(destAddr.sin_addr.s_addr), host->h_addr, host->h_length);
|
||||
ipAddress = inet_ntoa(destAddr.sin_addr);
|
||||
errorMessage(0, "Mapped %s to the following IP address: %s", argv[1],
|
||||
ipAddress);
|
||||
|
||||
if (CMT_OpenSSLConnection(control, sock, SSM_REQUEST_SSL_DATA_SSL,
|
||||
get_port_from_url(argv[1]), ipAddress,
|
||||
hostname, CM_FALSE, NULL) != CMTSuccess) {
|
||||
errorMessage(6, "Could not open SSL connection to %s.", argv[1]);
|
||||
}
|
||||
|
||||
getString = extract_get_target(argv[1]);
|
||||
sprintf(requestString,
|
||||
"GET %s HTTP/1.0\r\n"
|
||||
"\r\n", getString, hostname);
|
||||
APP_Send(sock, requestString, strlen(requestString));
|
||||
/*
|
||||
* Now all we have to do is sit here and fetch the data from the
|
||||
* socket.
|
||||
*/
|
||||
errorMessage (0, "About to print out the fetched page.");
|
||||
while ((selSock=APP_Select(&sock, 1, 0)) != NULL) {
|
||||
if (selSock == sock) {
|
||||
bytesRead = APP_Receive(sock, buffer, READ_BUFFER_SIZE-1);
|
||||
if (bytesRead == -1 || bytesRead == 0) {
|
||||
break;
|
||||
}
|
||||
buffer[bytesRead] = '\0';
|
||||
fprintf(stderr, buffer);
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"\n");
|
||||
if (bytesRead == -1) {
|
||||
errorMessage(7, "Error receiving decrypted data from psm.");
|
||||
}
|
||||
errorMessage(0, "Successfully read the entire page.");
|
||||
if (CMT_DestroyDataConnection(control, sock) != CMTSuccess) {
|
||||
errorMessage(8, "Error destroygin the SSL data connection "
|
||||
"with the psm server.");
|
||||
}
|
||||
if (CMT_CloseControlConnection(control) != CMTSuccess) {
|
||||
errorMessage(9, "Error closing the control connection.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../../..
|
||||
DEPTH = ../../..
|
||||
|
||||
DIRS = protocol client
|
||||
|
||||
#
|
||||
# these dirs are not built at the moment
|
||||
#
|
||||
#NOBUILD_DIRS = jar
|
|
@ -0,0 +1,65 @@
|
|||
#! gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = protocol
|
||||
MODULE = security
|
||||
|
||||
EXPORTS = \
|
||||
protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
obscure.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
CSRCS = newproto.c \
|
||||
templates.c \
|
||||
obscure.c \
|
||||
obspriv.c \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
PROGRAM =
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
#//
|
||||
#// 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.
|
||||
#//
|
||||
IGNORE_MANIFEST=1
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Makefile to build the ssl library
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
!if "$(MOZ_BITS)" == "16"
|
||||
!ifndef MOZ_DEBUG
|
||||
OPTIMIZER=-Os -UDEBUG -DNDEBUG
|
||||
!endif
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
!ifndef MAKE_OBJ_TYPE
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBNAME=protocol
|
||||
PDBFILE=$(LIBNAME).pdb
|
||||
|
||||
LINCS = -I$(PUBLIC)\security \
|
||||
-I$(PUBLIC)\nspr \
|
||||
-I$(DEPTH)\include \
|
||||
-I..\include
|
||||
|
||||
!ifndef OS_CONFIG
|
||||
OS_CONFIG = WIN$(MOZ_BITS)
|
||||
!endif
|
||||
|
||||
LCFLAGS = -DEXPORT_VERSION -DLIB_BUILD
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\newproto.obj \
|
||||
.\$(OBJDIR)\templates.obj \
|
||||
.\$(OBJDIR)\obscure.obj \
|
||||
.\$(OBJDIR)\obspriv.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBRARY=.\$(OBJDIR)\$(LIBNAME).lib
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// install headers
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
INSTALL_DIR=$(PUBLIC)\security
|
||||
INSTALL_FILE_LIST= protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
obscure.h \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
export:: INSTALL_FILES
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../../../..
|
||||
DEPTH = ../../../..
|
||||
|
||||
EXPORTS = \
|
||||
protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
obscure.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
CSRCS = newproto.c \
|
||||
templates.c \
|
||||
obscure.c \
|
||||
obspriv.c \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(subst /,_,$(shell uname -s)),OS2)
|
||||
CSRCS += os2_rand.c
|
||||
endif
|
||||
|
||||
# mac_rand.c
|
||||
# unix_rand.c
|
||||
# win_rand.c
|
||||
# prelib.c
|
||||
|
||||
REQUIRES = security dbm nspr
|
||||
|
||||
DEFINES += -DNSPR20
|
||||
|
||||
LIBRARY_NAME = protocol
|
|
@ -0,0 +1,596 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 __MESSAGES_H__
|
||||
#define __MESSAGES_H__
|
||||
|
||||
#include "newproto.h"
|
||||
|
||||
typedef struct SingleNumMessage {
|
||||
CMInt32 value;
|
||||
} SingleNumMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleNumMessageTemplate[];
|
||||
|
||||
typedef struct SingleStringMessage {
|
||||
char *string;
|
||||
} SingleStringMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleStringMessageTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage {
|
||||
CMTItem item;
|
||||
} SingleItemMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleItemMessageTemplate[];
|
||||
|
||||
typedef struct HelloRequest {
|
||||
CMInt32 version;
|
||||
CMInt32 policy;
|
||||
CMBool doesUI;
|
||||
char *profile;
|
||||
char* profileDir;
|
||||
} HelloRequest;
|
||||
|
||||
extern CMTMessageTemplate HelloRequestTemplate[];
|
||||
|
||||
typedef struct HelloReply {
|
||||
CMInt32 result;
|
||||
CMInt32 sessionID;
|
||||
CMInt32 version;
|
||||
CMInt32 httpPort;
|
||||
CMInt32 policy;
|
||||
CMTItem nonce;
|
||||
char *stringVersion;
|
||||
} HelloReply;
|
||||
|
||||
extern CMTMessageTemplate HelloReplyTemplate[];
|
||||
|
||||
typedef struct SSLDataConnectionRequest {
|
||||
CMInt32 flags;
|
||||
CMInt32 port;
|
||||
char *hostIP;
|
||||
char *hostName;
|
||||
CMBool forceHandshake;
|
||||
CMTItem clientContext;
|
||||
} SSLDataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate SSLDataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct TLSDataConnectionRequest {
|
||||
CMInt32 port;
|
||||
char* hostIP;
|
||||
char* hostName;
|
||||
} TLSDataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate TLSDataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct TLSStepUpRequest {
|
||||
CMUint32 connID;
|
||||
CMTItem clientContext;
|
||||
} TLSStepUpRequest;
|
||||
|
||||
extern CMTMessageTemplate TLSStepUpRequestTemplate[];
|
||||
|
||||
typedef struct ProxyStepUpRequest {
|
||||
CMUint32 connID;
|
||||
CMTItem clientContext;
|
||||
char* url;
|
||||
} ProxyStepUpRequest;
|
||||
|
||||
extern CMTMessageTemplate ProxyStepUpRequestTemplate[];
|
||||
|
||||
typedef struct PKCS7DataConnectionRequest {
|
||||
CMUint32 resID;
|
||||
CMTItem clientContext;
|
||||
} PKCS7DataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate PKCS7DataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct DataConnectionReply {
|
||||
CMInt32 result;
|
||||
CMInt32 connID;
|
||||
CMInt32 port;
|
||||
} DataConnectionReply;
|
||||
|
||||
extern CMTMessageTemplate DataConnectionReplyTemplate[];
|
||||
|
||||
typedef struct UIEvent {
|
||||
CMInt32 resourceID;
|
||||
CMInt32 width;
|
||||
CMInt32 height;
|
||||
char *url;
|
||||
CMTItem clientContext;
|
||||
} UIEvent;
|
||||
|
||||
extern CMTMessageTemplate UIEventTemplate[];
|
||||
|
||||
typedef struct TaskCompletedEvent {
|
||||
CMInt32 resourceID;
|
||||
CMInt32 numTasks;
|
||||
CMInt32 result;
|
||||
} TaskCompletedEvent;
|
||||
|
||||
extern CMTMessageTemplate TaskCompletedEventTemplate[];
|
||||
|
||||
typedef struct VerifyDetachedSigRequest {
|
||||
CMInt32 pkcs7ContentID;
|
||||
CMInt32 certUsage;
|
||||
CMInt32 hashAlgID;
|
||||
CMBool keepCert;
|
||||
CMTItem hash;
|
||||
} VerifyDetachedSigRequest;
|
||||
|
||||
extern CMTMessageTemplate VerifyDetachedSigRequestTemplate[];
|
||||
|
||||
typedef struct CreateSignedRequest {
|
||||
CMInt32 scertRID;
|
||||
CMInt32 ecertRID;
|
||||
CMInt32 dig_alg;
|
||||
CMTItem digest;
|
||||
} CreateSignedRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateSignedRequestTemplate[];
|
||||
|
||||
typedef struct CreateContentInfoReply {
|
||||
CMInt32 ciRID;
|
||||
CMInt32 result;
|
||||
CMInt32 errorCode;
|
||||
} CreateContentInfoReply;
|
||||
|
||||
extern CMTMessageTemplate CreateContentInfoReplyTemplate[];
|
||||
|
||||
typedef struct CreateEncryptedRequest {
|
||||
CMInt32 scertRID;
|
||||
CMInt32 nrcerts;
|
||||
CMInt32 *rcertRIDs;
|
||||
} CreateEncryptedRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateEncryptedRequestTemplate[];
|
||||
|
||||
typedef struct CreateResourceRequest {
|
||||
CMInt32 type;
|
||||
CMTItem params;
|
||||
} CreateResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateResourceRequestTemplate[];
|
||||
|
||||
typedef struct CreateResourceReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} CreateResourceReply;
|
||||
|
||||
extern CMTMessageTemplate CreateResourceReplyTemplate[];
|
||||
|
||||
typedef struct GetAttribRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 fieldID;
|
||||
} GetAttribRequest;
|
||||
|
||||
extern CMTMessageTemplate GetAttribRequestTemplate[];
|
||||
|
||||
typedef struct GetAttribReply {
|
||||
CMInt32 result;
|
||||
SSMAttributeValue value;
|
||||
} GetAttribReply;
|
||||
|
||||
extern CMTMessageTemplate GetAttribReplyTemplate[];
|
||||
|
||||
typedef struct SetAttribRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 fieldID;
|
||||
SSMAttributeValue value;
|
||||
} SetAttribRequest;
|
||||
|
||||
extern CMTMessageTemplate SetAttribRequestTemplate[];
|
||||
|
||||
typedef struct PickleResourceReply {
|
||||
CMInt32 result;
|
||||
CMTItem blob;
|
||||
} PickleResourceReply;
|
||||
|
||||
extern CMTMessageTemplate PickleResourceReplyTemplate[];
|
||||
|
||||
typedef struct UnpickleResourceRequest {
|
||||
CMInt32 resourceType;
|
||||
CMTItem resourceData;
|
||||
} UnpickleResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate UnpickleResourceRequestTemplate[];
|
||||
|
||||
typedef struct UnpickleResourceReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} UnpickleResourceReply;
|
||||
|
||||
extern CMTMessageTemplate UnpickleResourceReplyTemplate[];
|
||||
|
||||
typedef struct PickleSecurityStatusReply {
|
||||
CMInt32 result;
|
||||
CMInt32 securityLevel;
|
||||
CMTItem blob;
|
||||
} PickleSecurityStatusReply;
|
||||
|
||||
extern CMTMessageTemplate PickleSecurityStatusReplyTemplate[];
|
||||
|
||||
typedef struct DupResourceReply {
|
||||
CMInt32 result;
|
||||
CMUint32 resID;
|
||||
} DupResourceReply;
|
||||
|
||||
extern CMTMessageTemplate DupResourceReplyTemplate[];
|
||||
|
||||
typedef struct DestroyResourceRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 resType;
|
||||
} DestroyResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate DestroyResourceRequestTemplate[];
|
||||
|
||||
typedef struct VerifyCertRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 certUsage;
|
||||
} VerifyCertRequest;
|
||||
|
||||
extern CMTMessageTemplate VerifyCertRequestTemplate[];
|
||||
|
||||
typedef struct AddTempCertToDBRequest {
|
||||
CMInt32 resID;
|
||||
char *nickname;
|
||||
CMInt32 sslFlags;
|
||||
CMInt32 emailFlags;
|
||||
CMInt32 objSignFlags;
|
||||
} AddTempCertToDBRequest;
|
||||
|
||||
extern CMTMessageTemplate AddTempCertToDBRequestTemplate[];
|
||||
|
||||
typedef struct MatchUserCertRequest {
|
||||
CMInt32 certType;
|
||||
CMInt32 numCANames;
|
||||
char **caNames;
|
||||
} MatchUserCertRequest;
|
||||
|
||||
extern CMTMessageTemplate MatchUserCertRequestTemplate[];
|
||||
|
||||
typedef struct MatchUserCertReply {
|
||||
CMInt32 numCerts;
|
||||
CMInt32 *certs;
|
||||
} MatchUserCertReply;
|
||||
|
||||
extern CMTMessageTemplate MatchUserCertReplyTemplate[];
|
||||
|
||||
typedef struct EncodeCRMFReqRequest {
|
||||
CMInt32 numRequests;
|
||||
CMInt32 * reqIDs;
|
||||
} EncodeCRMFReqRequest;
|
||||
|
||||
extern CMTMessageTemplate EncodeCRMFReqRequestTemplate[];
|
||||
|
||||
typedef struct CMMFCertResponseRequest {
|
||||
char *nickname;
|
||||
char *base64Der;
|
||||
CMBool doBackup;
|
||||
CMTItem clientContext;
|
||||
} CMMFCertResponseRequest;
|
||||
|
||||
extern CMTMessageTemplate CMMFCertResponseRequestTemplate[];
|
||||
|
||||
typedef struct PasswordRequest {
|
||||
CMInt32 tokenKey;
|
||||
char *prompt;
|
||||
CMTItem clientContext;
|
||||
} PasswordRequest;
|
||||
|
||||
extern CMTMessageTemplate PasswordRequestTemplate[];
|
||||
|
||||
typedef struct PasswordReply {
|
||||
CMInt32 result;
|
||||
CMInt32 tokenID;
|
||||
char * passwd;
|
||||
} PasswordReply;
|
||||
|
||||
extern CMTMessageTemplate PasswordReplyTemplate[];
|
||||
|
||||
typedef struct KeyPairGenRequest {
|
||||
CMInt32 keyGenCtxtID;
|
||||
CMInt32 genMechanism;
|
||||
CMInt32 keySize;
|
||||
CMTItem params;
|
||||
} KeyPairGenRequest;
|
||||
|
||||
extern CMTMessageTemplate KeyPairGenRequestTemplate[];
|
||||
|
||||
typedef struct DecodeAndCreateTempCertRequest {
|
||||
CMInt32 type;
|
||||
CMTItem cert;
|
||||
} DecodeAndCreateTempCertRequest;
|
||||
|
||||
extern CMTMessageTemplate DecodeAndCreateTempCertRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleRequest {
|
||||
char *choiceString;
|
||||
char *challenge;
|
||||
char *typeString;
|
||||
char *pqgString;
|
||||
} GenKeyOldStyleRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleTokenRequest {
|
||||
CMInt32 rid;
|
||||
CMInt32 numtokens;
|
||||
char ** tokenNames;
|
||||
} GenKeyOldStyleTokenRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleTokenRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleTokenReply {
|
||||
CMInt32 rid;
|
||||
CMBool cancel;
|
||||
char * tokenName;
|
||||
} GenKeyOldStyleTokenReply;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleTokenReplyTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStylePasswordRequest {
|
||||
CMInt32 rid;
|
||||
char * tokenName;
|
||||
CMBool internal;
|
||||
CMInt32 minpwdlen;
|
||||
CMInt32 maxpwdlen;
|
||||
} GenKeyOldStylePasswordRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStylePasswordRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStylePasswordReply {
|
||||
CMInt32 rid;
|
||||
CMBool cancel;
|
||||
char * password;
|
||||
} GenKeyOldStylePasswordReply;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStylePasswordReplyTemplate[];
|
||||
|
||||
typedef struct GetKeyChoiceListRequest {
|
||||
char *type;
|
||||
char *pqgString;
|
||||
} GetKeyChoiceListRequest;
|
||||
|
||||
extern CMTMessageTemplate GetKeyChoiceListRequestTemplate[];
|
||||
|
||||
typedef struct GetKeyChoiceListReply {
|
||||
CMInt32 nchoices;
|
||||
char **choices;
|
||||
} GetKeyChoiceListReply;
|
||||
|
||||
extern CMTMessageTemplate GetKeyChoiceListReplyTemplate[];
|
||||
|
||||
typedef struct AddNewSecurityModuleRequest {
|
||||
char *moduleName;
|
||||
char *libraryPath;
|
||||
CMInt32 pubMechFlags;
|
||||
CMInt32 pubCipherFlags;
|
||||
} AddNewSecurityModuleRequest;
|
||||
|
||||
extern CMTMessageTemplate AddNewSecurityModuleRequestTemplate[];
|
||||
|
||||
typedef struct FilePathRequest {
|
||||
CMInt32 resID;
|
||||
char *prompt;
|
||||
CMBool getExistingFile;
|
||||
char *fileRegEx;
|
||||
} FilePathRequest;
|
||||
|
||||
extern CMTMessageTemplate FilePathRequestTemplate[];
|
||||
|
||||
typedef struct FilePathReply {
|
||||
CMInt32 resID;
|
||||
char *filePath;
|
||||
} FilePathReply;
|
||||
|
||||
extern CMTMessageTemplate FilePathReplyTemplate[];
|
||||
|
||||
typedef struct PasswordPromptReply {
|
||||
CMInt32 resID;
|
||||
char *promptReply;
|
||||
} PasswordPromptReply;
|
||||
|
||||
extern CMTMessageTemplate PasswordPromptReplyTemplate[];
|
||||
|
||||
typedef struct SignTextRequest {
|
||||
CMInt32 resID;
|
||||
char *stringToSign;
|
||||
char *hostName;
|
||||
char *caOption;
|
||||
CMInt32 numCAs;
|
||||
char** caNames;
|
||||
} SignTextRequest;
|
||||
|
||||
extern CMTMessageTemplate SignTextRequestTemplate[];
|
||||
|
||||
typedef struct GetLocalizedTextReply {
|
||||
CMInt32 whichString;
|
||||
char *localizedString;
|
||||
} GetLocalizedTextReply;
|
||||
|
||||
extern CMTMessageTemplate GetLocalizedTextReplyTemplate[];
|
||||
|
||||
typedef struct ImportCertReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} ImportCertReply;
|
||||
|
||||
extern CMTMessageTemplate ImportCertReplyTemplate[];
|
||||
|
||||
typedef struct PromptRequest {
|
||||
CMInt32 resID;
|
||||
char *prompt;
|
||||
CMTItem clientContext;
|
||||
} PromptRequest;
|
||||
|
||||
extern CMTMessageTemplate PromptRequestTemplate[];
|
||||
|
||||
typedef struct PromptReply {
|
||||
CMInt32 resID;
|
||||
CMBool cancel;
|
||||
char *promptReply;
|
||||
} PromptReply;
|
||||
|
||||
extern CMTMessageTemplate PromptReplyTemplate[];
|
||||
|
||||
typedef struct RedirectCompareReqeust {
|
||||
CMTItem socketStatus1Data;
|
||||
CMTItem socketStatus2Data;
|
||||
} RedirectCompareRequest;
|
||||
|
||||
extern CMTMessageTemplate RedirectCompareRequestTemplate[];
|
||||
|
||||
typedef struct DecodeAndAddCRLRequest {
|
||||
CMTItem derCrl;
|
||||
CMUint32 type;
|
||||
char *url;
|
||||
} DecodeAndAddCRLRequest;
|
||||
|
||||
extern CMTMessageTemplate DecodeAndAddCRLRequestTemplate[];
|
||||
|
||||
typedef struct SecurityAdvisorRequest {
|
||||
CMInt32 infoContext;
|
||||
CMInt32 resID;
|
||||
char * hostname;
|
||||
char * senderAddr;
|
||||
CMUint32 encryptedP7CInfo;
|
||||
CMUint32 signedP7CInfo;
|
||||
CMInt32 decodeError;
|
||||
CMInt32 verifyError;
|
||||
CMBool encryptthis;
|
||||
CMBool signthis;
|
||||
CMInt32 numRecipients;
|
||||
char ** recipients;
|
||||
} SecurityAdvisorRequest;
|
||||
|
||||
extern CMTMessageTemplate SecurityAdvisorRequestTemplate[];
|
||||
|
||||
/* "SecurityConfig" javascript related message templates */
|
||||
typedef struct SCAddTempCertToPermDBRequest {
|
||||
CMTItem certKey;
|
||||
char* trustStr;
|
||||
char* nickname;
|
||||
} SCAddTempCertToPermDBRequest;
|
||||
|
||||
extern CMTMessageTemplate SCAddTempCertToPermDBRequestTemplate[];
|
||||
|
||||
typedef struct SCDeletePermCertsRequest {
|
||||
CMTItem certKey;
|
||||
CMBool deleteAll;
|
||||
} SCDeletePermCertsRequest;
|
||||
|
||||
extern CMTMessageTemplate SCDeletePermCertsRequestTemplate[];
|
||||
|
||||
typedef struct TimeMessage {
|
||||
CMInt32 year;
|
||||
CMInt32 month;
|
||||
CMInt32 day;
|
||||
CMInt32 hour;
|
||||
CMInt32 minute;
|
||||
CMInt32 second;
|
||||
} TimeMessage;
|
||||
|
||||
extern CMTMessageTemplate TimeMessageTemplate[];
|
||||
|
||||
typedef struct CertEnumElement {
|
||||
char* name;
|
||||
CMTItem certKey;
|
||||
} CertEnumElement;
|
||||
|
||||
typedef struct SCCertIndexEnumReply {
|
||||
int length;
|
||||
CertEnumElement* list;
|
||||
} SCCertIndexEnumReply;
|
||||
|
||||
extern CMTMessageTemplate SCCertIndexEnumReplyTemplate[];
|
||||
|
||||
/* Test message */
|
||||
typedef struct TestListElement {
|
||||
char * name;
|
||||
char * value;
|
||||
} TestListElement;
|
||||
|
||||
typedef struct TestList {
|
||||
char *listName;
|
||||
int numElements;
|
||||
TestListElement *elements;
|
||||
} TestList;
|
||||
|
||||
extern CMTMessageTemplate TestListTemplate[];
|
||||
|
||||
/* Preference-related structs */
|
||||
typedef struct SetPrefElement {
|
||||
char* key;
|
||||
char* value;
|
||||
CMInt32 type;
|
||||
} SetPrefElement;
|
||||
|
||||
typedef struct SetPrefListMessage {
|
||||
int length;
|
||||
SetPrefElement* list;
|
||||
} SetPrefListMessage;
|
||||
|
||||
extern CMTMessageTemplate SetPrefListMessageTemplate[];
|
||||
|
||||
typedef struct GetPrefElement {
|
||||
char* key;
|
||||
CMInt32 type;
|
||||
} GetPrefElement;
|
||||
|
||||
typedef struct GetPrefListRequest {
|
||||
int length;
|
||||
GetPrefElement* list;
|
||||
} GetPrefListRequest;
|
||||
|
||||
extern CMTMessageTemplate GetPrefListRequestTemplate[];
|
||||
|
||||
typedef struct GetCertExtension {
|
||||
CMUint32 resID;
|
||||
CMUint32 extension;
|
||||
} GetCertExtension;
|
||||
|
||||
extern CMTMessageTemplate GetCertExtensionTemplate[];
|
||||
|
||||
typedef struct HTMLCertInfoRequest {
|
||||
CMUint32 certID;
|
||||
CMUint32 showImages;
|
||||
CMUint32 showIssuer;
|
||||
} HTMLCertInfoRequest;
|
||||
|
||||
extern CMTMessageTemplate HTMLCertInfoRequestTemplate[];
|
||||
|
||||
#endif /* __MESSAGES_H__ */
|
|
@ -0,0 +1,602 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#endif
|
||||
|
||||
#include "newproto.h"
|
||||
|
||||
char SSMVersionString[] = "1.1";
|
||||
|
||||
CMT_Alloc_fn cmt_alloc = malloc;
|
||||
CMT_Free_fn cmt_free = free;
|
||||
|
||||
#define ASSERT(x) assert(x)
|
||||
|
||||
#define CM_ntohl ntohl
|
||||
#define CM_htonl htonl
|
||||
|
||||
|
||||
/*************************************************************
|
||||
*
|
||||
* CMT_Init
|
||||
*
|
||||
*
|
||||
************************************************************/
|
||||
void
|
||||
CMT_Init(CMT_Alloc_fn allocfn, CMT_Free_fn freefn)
|
||||
{
|
||||
cmt_alloc = allocfn;
|
||||
cmt_free = freefn;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
decode_int(unsigned char **curptr, void *dest, CMInt32 *remaining)
|
||||
{
|
||||
CMInt32 datalen = sizeof(CMInt32);
|
||||
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
*(CMInt32 *)dest = ntohl(**(CMInt32 **)curptr);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
decode_string(unsigned char **curptr, CMInt32 *len,
|
||||
unsigned char **data, CMInt32 *remaining)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMInt32 datalen;
|
||||
|
||||
rv = decode_int(curptr, len, remaining);
|
||||
if (rv != CMTSuccess)
|
||||
return CMTFailure;
|
||||
|
||||
/* NULL string */
|
||||
if (*len == 0) {
|
||||
*data = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
datalen = (*len + 3) & ~3;
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
|
||||
*data = (unsigned char *) cmt_alloc(*len + 1);
|
||||
if (*data == NULL)
|
||||
return CMTFailure;
|
||||
|
||||
memcpy(*data, *curptr, *len);
|
||||
(*data)[*len] = 0;
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* CMT_DecodeMessage
|
||||
*
|
||||
* Decode msg into dest as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_DecodeMessage(CMTMessageTemplate *tmpl, void *dest, CMTItem *msg)
|
||||
{
|
||||
unsigned char *curptr, *destptr, *list;
|
||||
void ** ptr;
|
||||
CMInt32 remaining, len, choiceID = 0, listSize, listCount = 0;
|
||||
CMBool inChoice = CM_FALSE, foundChoice = CM_FALSE, inList = CM_FALSE;
|
||||
CMInt32 listItemSize = 0;
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
curptr = msg->data;
|
||||
remaining = msg->len;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
/* XXX Maybe this should be a more formal state machine? */
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
destptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else {
|
||||
if (inStructList) {
|
||||
destptr = tmpl->offset + list;
|
||||
} else {
|
||||
destptr = tmpl->offset + (unsigned char *)dest;
|
||||
}
|
||||
}
|
||||
switch (tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
rv = decode_string(&curptr, &len, (unsigned char **)destptr,
|
||||
&remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
rv = decode_string(&curptr, (long *) &((CMTItem *)destptr)->len,
|
||||
&((CMTItem *)destptr)->data, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
/* XXX This is too complicated */
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)destptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
if (listSize == 0) {
|
||||
list = NULL;
|
||||
} else {
|
||||
list = (unsigned char *) cmt_alloc(listSize * listItemSize);
|
||||
}
|
||||
*(void **)(tmpl->offset + (unsigned char *)dest) = list;
|
||||
inList = CM_TRUE;
|
||||
listCount = 0;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
/* XXX This is too complicated */
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)destptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
ptr = (void**)(tmpl->offset + (unsigned char *)dest);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (listSize == 0) {
|
||||
list = NULL;
|
||||
} else {
|
||||
list = (unsigned char *) cmt_alloc(listSize * listItemSize);
|
||||
}
|
||||
*ptr = list;
|
||||
inStructList = CM_TRUE;
|
||||
listCount = 0;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
choiceID = *(CMInt32 *)destptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
loser:
|
||||
/* Free the data buffer */
|
||||
if (msg->data) {
|
||||
cmt_free(msg->data);
|
||||
msg->data = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
calc_msg_len(CMTMessageTemplate *tmpl, void *src, CMInt32 *len_out)
|
||||
{
|
||||
CMInt32 len = 0, choiceID = 0, listSize, listItemSize, listCount;
|
||||
unsigned char *srcptr, *list;
|
||||
CMBool inChoice = CM_FALSE, inList = CM_FALSE, foundChoice = CM_FALSE;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
srcptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else if (inStructList) {
|
||||
srcptr = tmpl->offset + list;
|
||||
} else {
|
||||
srcptr = tmpl->offset + (unsigned char *)src;
|
||||
}
|
||||
switch(tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
len += sizeof(CMInt32);
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
len += sizeof(CMInt32);
|
||||
/* Non NULL string */
|
||||
if (*(char**)srcptr) {
|
||||
len += (strlen(*(char**)srcptr) + 4) & ~3;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
len += sizeof(CMInt32);
|
||||
len += (((CMTItem *)srcptr)->len + 3) & ~3;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
len += sizeof(CMInt32);
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);
|
||||
listCount = 0;
|
||||
inList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
len += sizeof(CMInt32);
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
listCount = 0;
|
||||
inStructList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
len += sizeof(CMInt32);
|
||||
choiceID = *(CMInt32 *)srcptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
*len_out = len;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
encode_int(unsigned char **curptr, void *src, CMInt32 *remaining)
|
||||
{
|
||||
CMInt32 datalen = sizeof(CMInt32);
|
||||
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
**(CMInt32 **)curptr = CM_htonl(*(CMInt32 *)src);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
encode_string(unsigned char **curptr, CMInt32 len,
|
||||
unsigned char *data, CMInt32 *remaining)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMInt32 datalen;
|
||||
|
||||
rv = encode_int(curptr, &len, remaining);
|
||||
if (rv != CMTSuccess)
|
||||
return CMTFailure;
|
||||
|
||||
/* NULL string */
|
||||
if (len == 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
datalen = (len + 3) & ~3;
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
|
||||
memcpy(*curptr, data, len);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* CMT_EncodeMessage
|
||||
*
|
||||
* Encode src into msg as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_EncodeMessage(CMTMessageTemplate *tmpl, CMTItem *msg, void *src)
|
||||
{
|
||||
CMInt32 choiceID = 0, listSize, listItemSize, listCount, remaining;
|
||||
unsigned char *srcptr, *curptr, *list;
|
||||
CMBool inChoice = CM_FALSE, inList = CM_FALSE, foundChoice = CM_FALSE;
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
rv = calc_msg_len(tmpl, src, (long *) &msg->len);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
curptr = msg->data = (unsigned char *) cmt_alloc(msg->len);
|
||||
if(msg->data == NULL)
|
||||
goto loser;
|
||||
remaining = msg->len;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
srcptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else {
|
||||
if (inStructList) {
|
||||
srcptr = tmpl->offset + list;
|
||||
} else {
|
||||
srcptr = tmpl->offset + (unsigned char *)src;
|
||||
}
|
||||
}
|
||||
switch(tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
if (*(char**)srcptr) {
|
||||
/* Non NULL string */
|
||||
rv = encode_string(&curptr, (long) strlen(*(char**)srcptr),
|
||||
*(unsigned char**)srcptr, &remaining);
|
||||
} else {
|
||||
/* NULL string */
|
||||
rv = encode_string(&curptr, 0L, *(unsigned char**)srcptr, &remaining);
|
||||
}
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
rv = encode_string(&curptr, ((CMTItem *)srcptr)->len,
|
||||
((CMTItem *)srcptr)->data, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);
|
||||
listCount = 0;
|
||||
inList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
listCount = 0;
|
||||
inStructList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
choiceID = *(CMInt32 *)srcptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 __NEWPROTO_H__
|
||||
#define __NEWPROTO_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ssmdefs.h"
|
||||
|
||||
typedef enum CMTDataType {
|
||||
CMT_DT_END,
|
||||
CMT_DT_RID,
|
||||
CMT_DT_INT,
|
||||
CMT_DT_BOOL,
|
||||
CMT_DT_STRING,
|
||||
CMT_DT_ITEM,
|
||||
CMT_DT_LIST,
|
||||
CMT_DT_CHOICE,
|
||||
CMT_DT_END_CHOICE,
|
||||
CMT_DT_STRUCT_LIST,
|
||||
CMT_DT_END_STRUCT_LIST,
|
||||
CMT_DT_STRUCT_PTR,
|
||||
} CMTDataType;
|
||||
|
||||
typedef struct CMTMessageTemplate {
|
||||
CMTDataType type;
|
||||
CMUint32 offset;
|
||||
CMInt32 validator;
|
||||
CMInt32 choiceID;
|
||||
} CMTMessageTemplate;
|
||||
|
||||
typedef struct CMTMessageHeader {
|
||||
CMInt32 type;
|
||||
CMInt32 len;
|
||||
} CMTMessageHeader;
|
||||
|
||||
typedef void *(* CMT_Alloc_fn) (size_t size);
|
||||
typedef void (* CMT_Free_fn)(void * ptr);
|
||||
|
||||
extern CMT_Alloc_fn cmt_alloc;
|
||||
extern CMT_Free_fn cmt_free;
|
||||
|
||||
/*************************************************************
|
||||
*
|
||||
* CMT_Init
|
||||
*
|
||||
*
|
||||
************************************************************/
|
||||
void
|
||||
CMT_Init(CMT_Alloc_fn allocfn, CMT_Free_fn freefn);
|
||||
|
||||
/*************************************************************
|
||||
* CMT_DecodeMessage
|
||||
*
|
||||
* Decode msg into dest as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_DecodeMessage(CMTMessageTemplate *tmpl, void *dest, CMTItem *msg);
|
||||
|
||||
|
||||
/*************************************************************
|
||||
* CMT_EncodeMessage
|
||||
*
|
||||
* Encode src into msg as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_EncodeMessage(CMTMessageTemplate *tmpl, CMTItem *msg, void *src);
|
||||
|
||||
|
||||
#endif /* __NEWPROTO_H__ */
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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 "obspriv.h"
|
||||
#include "newproto.h"
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
Originally this code was used to obscure the control messages
|
||||
traveling between processes. With the relaxation of export rules,
|
||||
this whole step is no longer necessary, and is included for
|
||||
informational purposes only. (We need to finish removing the
|
||||
obscuring code.)
|
||||
*/
|
||||
struct obscureNOPStr {
|
||||
SSMObscureObject * obj;
|
||||
};
|
||||
|
||||
typedef struct obscureNOPStr obscureV1;
|
||||
|
||||
static int
|
||||
ssmObscure_Destroy(void * privData)
|
||||
{
|
||||
obscureV1 * priv = (obscureV1 *)privData;
|
||||
|
||||
memset(priv, 0, sizeof *priv);
|
||||
cmt_free(priv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_Send(void * privData, void * buf, unsigned int len)
|
||||
{
|
||||
/* obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
/* NOP */
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_Recv(void * privData, void * buf, unsigned int len)
|
||||
{
|
||||
/*obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
/* NOP */
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_SendInit(void * privData, void * buf)
|
||||
{
|
||||
/*obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_RecvInit(void * privData, void * buf, unsigned int len,
|
||||
SSMObscureBool * pDone)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
ssmObscure_InitPrivate(SSMObscureObject * obj, SSMObscureBool IsServer)
|
||||
{
|
||||
obscureV1 * priv = (obscureV1 *) cmt_alloc(sizeof (obscureV1));
|
||||
|
||||
if (!priv)
|
||||
return NULL;
|
||||
|
||||
priv->obj = obj;
|
||||
return priv;
|
||||
}
|
||||
|
||||
obsInitFn SSMObscure_InitPrivate = ssmObscure_InitPrivate;
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 __SSM_RSRCIDS_H__
|
||||
#define __SSM_RSRCIDS_H__
|
||||
|
||||
#include "ssmdefs.h"
|
||||
|
||||
/*
|
||||
* IMPORTANT:
|
||||
*
|
||||
* To preserve backward compatibility as much as possible, always add new
|
||||
* values to either one of the enumeration tables at the end of the table.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SSM_RESTYPE_NULL = 0L,
|
||||
SSM_RESTYPE_RESOURCE,
|
||||
SSM_RESTYPE_CONNECTION,
|
||||
SSM_RESTYPE_CONTROL_CONNECTION,
|
||||
SSM_RESTYPE_DATA_CONNECTION,
|
||||
SSM_RESTYPE_SSL_DATA_CONNECTION,
|
||||
SSM_RESTYPE_PKCS7_DECODE_CONNECTION,
|
||||
SSM_RESTYPE_PKCS7_ENCODE_CONNECTION,
|
||||
SSM_RESTYPE_HASH_CONNECTION,
|
||||
|
||||
SSM_RESTYPE_CERTIFICATE,
|
||||
SSM_RESTYPE_SSL_SOCKET_STATUS,
|
||||
SSM_RESTYPE_PKCS7_CONTENT_INFO,
|
||||
SSM_RESTYPE_KEY_PAIR,
|
||||
SSM_RESTYPE_CRMF_REQUEST,
|
||||
SSM_RESTYPE_KEYGEN_CONTEXT,
|
||||
SSM_RESTYPE_SECADVISOR_CONTEXT,
|
||||
SSM_RESTYPE_SIGNTEXT,
|
||||
SSM_RESTYPE_PKCS12_CONTEXT,
|
||||
SSM_RESTYPE_MAX
|
||||
} SSMResourceType;
|
||||
|
||||
/* Attribute/resource types */
|
||||
|
||||
/* Attribute IDs */
|
||||
typedef enum
|
||||
{
|
||||
SSM_FID_NULL = (CMUint32) 0, /* placeholder */
|
||||
|
||||
/* Connection attributes */
|
||||
SSM_FID_CONN_ALIVE,
|
||||
SSM_FID_CONN_PARENT,
|
||||
|
||||
/* Data connection attributes */
|
||||
SSM_FID_CONN_DATA_PENDING,
|
||||
|
||||
/* SSL data connection attributes */
|
||||
SSM_FID_SSLDATA_SOCKET_STATUS,
|
||||
SSM_FID_SSLDATA_ERROR_VALUE,
|
||||
|
||||
/* PKCS7 decode connection attributes */
|
||||
SSM_FID_P7CONN_CONTENT_INFO,
|
||||
SSM_FID_P7CONN_RETURN_VALUE,
|
||||
SSM_FID_P7CONN_ERROR_VALUE,
|
||||
|
||||
/* Hash connection attributes */
|
||||
SSM_FID_HASHCONN_RESULT,
|
||||
|
||||
/* Certificate attributes */
|
||||
SSM_FID_CERT_SUBJECT_NAME,
|
||||
SSM_FID_CERT_ISSUER_NAME,
|
||||
SSM_FID_CERT_SERIAL_NUMBER,
|
||||
SSM_FID_CERT_EXP_DATE,
|
||||
SSM_FID_CERT_FINGERPRINT,
|
||||
SSM_FID_CERT_COMMON_NAME,
|
||||
SSM_FID_CERT_NICKNAME,
|
||||
SSM_FID_CERT_ORG_NAME,
|
||||
SSM_FID_CERT_HTML_CERT,
|
||||
SSM_FID_CERT_PICKLE_CERT,
|
||||
SSM_FID_CERT_CERTKEY,
|
||||
SSM_FID_CERT_FIND_CERT_ISSUER,
|
||||
SSM_FID_CERT_EMAIL_ADDRESS,
|
||||
SSM_FID_CERT_ISPERM,
|
||||
|
||||
/* SSL socket status attributes */
|
||||
SSM_FID_SSS_KEYSIZE,
|
||||
SSM_FID_SSS_SECRET_KEYSIZE,
|
||||
SSM_FID_SSS_CERT_ID,
|
||||
SSM_FID_SSS_CIPHER_NAME,
|
||||
SSM_FID_SSS_SECURITY_LEVEL,
|
||||
SSM_FID_SSS_HTML_STATUS,
|
||||
|
||||
/* PKCS7 content info attributes */
|
||||
SSM_FID_P7CINFO_IS_SIGNED,
|
||||
SSM_FID_P7CINFO_IS_ENCRYPTED,
|
||||
SSM_FID_P7CINFO_SIGNER_CERT,
|
||||
|
||||
/* CRMF ID's */
|
||||
SSM_FID_CRMFREQ_REGTOKEN,
|
||||
SSM_FID_CRMFREQ_AUTHENTICATOR,
|
||||
SSM_FID_CRMFREQ_EXTENSIONS,
|
||||
SSM_FID_CRMFREQ_KEY_TYPE,
|
||||
SSM_FID_CRMFREQ_DN,
|
||||
|
||||
/* Security advisor context */
|
||||
SSM_FID_SECADVISOR_URL,
|
||||
SSM_FID_SECADVISOR_WIDTH,
|
||||
SSM_FID_SECADVISOR_HEIGHT,
|
||||
|
||||
/* Sign Text */
|
||||
SSM_FID_SIGNTEXT_RESULT,
|
||||
|
||||
/* Key Gen ID's */
|
||||
SSM_FID_KEYGEN_ESCROW_AUTHORITY,
|
||||
|
||||
/* Key Pair ID's */
|
||||
SSM_FID_KEYPAIR_KEY_GEN_TYPE,
|
||||
|
||||
/* Session Attributes */
|
||||
SSM_FID_DEFAULT_EMAIL_RECIPIENT_CERT,
|
||||
SSM_FID_DEFAULT_EMAIL_SIGNER_CERT,
|
||||
|
||||
/* Client Context Attribute */
|
||||
SSM_FID_CLIENT_CONTEXT,
|
||||
|
||||
/* Resource Error */
|
||||
SSM_FID_RESOURCE_ERROR,
|
||||
|
||||
SSM_FID_KEYGEN_SLOT_NAME,
|
||||
SSM_FID_DISABLE_ESCROW_WARN,
|
||||
SSM_FID_KEYGEN_TOKEN_NAME,
|
||||
|
||||
SSM_FID_SSLDATA_DISCARD_SOCKET_STATUS,
|
||||
|
||||
SSM_FID_MAX /* placeholder */
|
||||
} SSMAttributeID;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,354 @@
|
|||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 __SSMDEFS_H__
|
||||
#define __SSMDEFS_H__
|
||||
|
||||
/* Basic type definitions for both client and server. */
|
||||
#ifdef macintosh
|
||||
typedef unsigned long size_t;
|
||||
typedef long ptrdiff_t;
|
||||
#endif
|
||||
typedef long CMInt32;
|
||||
typedef unsigned long CMUint32;
|
||||
typedef long SSMResourceID;
|
||||
#ifdef XP_MAC
|
||||
/* in order to get around Mac compiler pedanticism */
|
||||
#define SSMStatus int
|
||||
#else
|
||||
typedef int SSMStatus;
|
||||
#endif
|
||||
|
||||
#define PSM_PORT 11111
|
||||
#define PSM_DATA_PORT 11113 /* needs to be removed */
|
||||
|
||||
typedef enum _CMTStatus {
|
||||
CMTFailure = -1,
|
||||
CMTSuccess = 0
|
||||
} CMTStatus;
|
||||
|
||||
typedef enum {
|
||||
CM_FALSE = 0,
|
||||
CM_TRUE = 1
|
||||
} CMBool;
|
||||
|
||||
typedef struct CMTItemStr {
|
||||
CMUint32 type;
|
||||
unsigned char *data;
|
||||
unsigned int len;
|
||||
} CMTItem;
|
||||
|
||||
/* A length-encoded string. */
|
||||
struct _SSMString {
|
||||
CMUint32 m_length;
|
||||
char m_data;
|
||||
};
|
||||
typedef struct _SSMString SSMString;
|
||||
|
||||
#define SSM_PROTOCOL_VERSION 0x00000051
|
||||
|
||||
#define SSM_INVALID_RESOURCE 0x00000000
|
||||
#define SSM_GLOBAL_RESOURCE 0x00000001
|
||||
#define SSM_SESSION_RESOURCE 0x00000002
|
||||
|
||||
/* Message category flags */
|
||||
typedef enum
|
||||
{
|
||||
SSM_REQUEST_MESSAGE = 0x10000000,
|
||||
SSM_REPLY_OK_MESSAGE = 0x20000000,
|
||||
SSM_REPLY_ERR_MESSAGE = 0x30000000,
|
||||
SSM_EVENT_MESSAGE = 0x40000000
|
||||
} SSMMessageCategory;
|
||||
|
||||
/* Message types */
|
||||
typedef enum
|
||||
{
|
||||
SSM_DATA_CONNECTION = 0x00001000,
|
||||
SSM_OBJECT_SIGNING = 0x00002000,
|
||||
SSM_RESOURCE_ACTION = 0x00003000,
|
||||
SSM_CERT_ACTION = 0x00004000,
|
||||
SSM_PKCS11_ACTION = 0x00005000,
|
||||
SSM_CRMF_ACTION = 0x00006000,
|
||||
SSM_FORMSIGN_ACTION = 0x00007000,
|
||||
SSM_LOCALIZED_TEXT = 0x00008000,
|
||||
SSM_HELLO_MESSAGE = 0x00009000,
|
||||
SSM_SECURITY_ADVISOR = 0x0000a000,
|
||||
SSM_SEC_CFG_ACTION = 0x0000b000,
|
||||
SSM_KEYGEN_TAG = 0x0000c000,
|
||||
SSM_PREF_ACTION = 0x0000d000,
|
||||
SSM_MISC_ACTION = 0x0000f000
|
||||
} SSMMessageType;
|
||||
|
||||
|
||||
/* Data connection messages subtypes */
|
||||
typedef enum
|
||||
{
|
||||
SSM_SSL_CONNECTION = 0x00000100,
|
||||
SSM_PKCS7DECODE_STREAM = 0x00000200,
|
||||
SSM_PKCS7ENCODE_STREAM = 0x00000300,
|
||||
SSM_HASH_STREAM = 0x00000400,
|
||||
SSM_TLS_CONNECTION = 0x00000500,
|
||||
SSM_PROXY_CONNECTION = 0x00000600
|
||||
} SSMDataConnectionSType;
|
||||
|
||||
/* Object signing message subtypes */
|
||||
typedef enum
|
||||
{
|
||||
SSM_VERIFY_RAW_SIG = 0x00000100,
|
||||
SSM_VERIFY_DETACHED_SIG= 0x00000200,
|
||||
SSM_CREATE_SIGNED = 0x00000300,
|
||||
SSM_CREATE_ENCRYPTED = 0x00000400
|
||||
} SSMObjSignSType;
|
||||
|
||||
/* Resource access messages subtypes */
|
||||
typedef enum
|
||||
{
|
||||
SSM_CREATE_RESOURCE = 0x00000100,
|
||||
SSM_DESTROY_RESOURCE = 0x00000200,
|
||||
SSM_GET_ATTRIBUTE = 0x00000300,
|
||||
SSM_CONSERVE_RESOURCE = 0x00000400,
|
||||
SSM_DUPLICATE_RESOURCE = 0x00000500,
|
||||
SSM_SET_ATTRIBUTE = 0x00000600,
|
||||
SSM_TLS_STEPUP = 0x00000700,
|
||||
SSM_PROXY_STEPUP = 0x00000800
|
||||
} SSMResourceAccessSType;
|
||||
|
||||
/* Further specification for resource access messages */
|
||||
typedef enum {
|
||||
SSM_SSLSocket_Status = 0x00000010
|
||||
} SSMCreateResource;
|
||||
|
||||
typedef enum {
|
||||
SSM_NO_ATTRIBUTE = 0x00000000,
|
||||
SSM_NUMERIC_ATTRIBUTE = 0x00000010,
|
||||
SSM_STRING_ATTRIBUTE = 0x00000020,
|
||||
SSM_RID_ATTRIBUTE = 0x00000030
|
||||
} SSMResourceAttrType;
|
||||
|
||||
typedef enum {
|
||||
SSM_PICKLE_RESOURCE = 0x00000010,
|
||||
SSM_UNPICKLE_RESOURCE = 0x00000020,
|
||||
SSM_PICKLE_SECURITY_STATUS = 0x00000030
|
||||
} SSMResourceConsv;
|
||||
|
||||
/* Certificate access message subtypes */
|
||||
typedef enum
|
||||
{
|
||||
SSM_IMPORT_CERT = 0x00000100,
|
||||
SSM_VERIFY_CERT = 0x00000200,
|
||||
SSM_FIND_BY_NICKNAME = 0x00000300,
|
||||
SSM_FIND_BY_KEY = 0x00000400,
|
||||
SSM_FIND_BY_EMAILADDR = 0x00000500,
|
||||
SSM_ADD_TO_DB = 0x00000600,
|
||||
SSM_DECODE_CERT = 0x00000700,
|
||||
SSM_MATCH_USER_CERT = 0x00000800,
|
||||
SSM_DESTROY_CERT = 0x00000900,
|
||||
SSM_DECODE_TEMP_CERT = 0x00000a00,
|
||||
SSM_REDIRECT_COMPARE = 0x00000b00,
|
||||
SSM_DECODE_CRL = 0x00000c00,
|
||||
SSM_EXTENSION_VALUE = 0x00000d00,
|
||||
SSM_HTML_INFO = 0x00000e00
|
||||
} SSMCertAccessSType;
|
||||
|
||||
/* message subtypes used for KEYGEN form tag */
|
||||
typedef enum
|
||||
{
|
||||
|
||||
SSM_GET_KEY_CHOICE = 0x00000100,
|
||||
SSM_KEYGEN_START = 0x00000200,
|
||||
SSM_KEYGEN_TOKEN = 0x00000300,
|
||||
SSM_KEYGEN_PASSWORD = 0x00000400,
|
||||
SSM_KEYGEN_DONE = 0x00000500
|
||||
} SSMKeyGenTagProcessType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SSM_CREATE_KEY_PAIR = 0x00000100,
|
||||
SSM_FINISH_KEY_GEN = 0x00000200,
|
||||
SSM_ADD_NEW_MODULE = 0x00000300,
|
||||
SSM_DEL_MODULE = 0x00000400,
|
||||
SSM_LOGOUT_ALL = 0x00000500,
|
||||
SSM_ENABLED_CIPHERS = 0x00000600
|
||||
} SSMPKCS11Actions;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SSM_CREATE_CRMF_REQ = 0x00000100,
|
||||
SSM_DER_ENCODE_REQ = 0x00000200,
|
||||
SSM_PROCESS_CMMF_RESP = 0x00000300,
|
||||
SSM_CHALLENGE = 0x00000400
|
||||
} SSMCRMFAction;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SSM_SIGN_TEXT = 0x00000100
|
||||
} SSMFormSignAction;
|
||||
|
||||
/* Security Config subtypes */
|
||||
typedef enum
|
||||
{
|
||||
SSM_ADD_CERT_TO_TEMP_DB = 0x00000100,
|
||||
SSM_ADD_TEMP_CERT_TO_DB = 0x00000200,
|
||||
SSM_DELETE_PERM_CERTS = 0x00000300,
|
||||
SSM_FIND_CERT_KEY = 0x00000400,
|
||||
SSM_GET_CERT_PROP_BY_KEY = 0x00000500,
|
||||
SSM_CERT_INDEX_ENUM = 0x00000600
|
||||
} SSMSecCfgAction;
|
||||
|
||||
/* subcategories for SSM_FIND_CERT_KEY and SSM_CERT_INDEX_ENUM */
|
||||
typedef enum
|
||||
{
|
||||
SSM_FIND_KEY_BY_NICKNAME = 0x00000010,
|
||||
SSM_FIND_KEY_BY_EMAIL_ADDR = 0x00000020,
|
||||
SSM_FIND_KEY_BY_DN = 0x00000030
|
||||
} SSMSecCfgFindByType;
|
||||
|
||||
/* subcategories for SSM_GET_CERT_PROP_BY_KEY */
|
||||
typedef enum
|
||||
{
|
||||
SSM_SECCFG_GET_NICKNAME = 0x00000010,
|
||||
SSM_SECCFG_GET_EMAIL_ADDR = 0x00000020,
|
||||
SSM_SECCFG_GET_DN = 0x00000030,
|
||||
SSM_SECCFG_GET_TRUST = 0x00000040,
|
||||
SSM_SECCFG_CERT_IS_PERM = 0x00000050,
|
||||
SSM_SECCFG_GET_NOT_BEFORE = 0x00000060,
|
||||
SSM_SECCFG_GET_NOT_AFTER = 0x00000070,
|
||||
SSM_SECCFG_GET_SERIAL_NO = 0x00000080,
|
||||
SSM_SECCFG_GET_ISSUER = 0x00000090,
|
||||
SSM_SECCFG_GET_ISSUER_KEY = 0x000000a0,
|
||||
SSM_SECCFG_GET_SUBJECT_NEXT = 0x000000b0,
|
||||
SSM_SECCFG_GET_SUBJECT_PREV = 0x000000c0
|
||||
} SSMSecCfgGetCertPropType;
|
||||
|
||||
/* Misc requests */
|
||||
typedef enum
|
||||
{
|
||||
SSM_MISC_GET_RNG_DATA = 0x00000100,
|
||||
SSM_MISC_PUT_RNG_DATA = 0x00000200
|
||||
} SSMMiscRequestType;
|
||||
|
||||
/* Type masks for message types */
|
||||
typedef enum
|
||||
{
|
||||
SSM_CATEGORY_MASK = 0xF0000000,
|
||||
SSM_TYPE_MASK = 0x0000F000,
|
||||
SSM_SUBTYPE_MASK = 0x00000F00,
|
||||
SSM_SPECIFIC_MASK = 0x000000F0
|
||||
} SSMMessageMaskType;
|
||||
|
||||
typedef struct SSMAttributeValue {
|
||||
SSMResourceAttrType type;
|
||||
union {
|
||||
SSMResourceID rid;
|
||||
CMTItem string;
|
||||
CMInt32 numeric;
|
||||
} u;
|
||||
} SSMAttributeValue;
|
||||
|
||||
typedef enum {
|
||||
rsaEnc, rsaDualUse, rsaSign, rsaNonrepudiation, rsaSignNonrepudiation,
|
||||
dhEx, dsaSignNonrepudiation, dsaSign, dsaNonrepudiation, invalidKeyGen
|
||||
} SSMKeyGenType;
|
||||
|
||||
typedef enum {
|
||||
ssmUnknownPolicy=-1,ssmDomestic=0, ssmExport=1, ssmFrance=2
|
||||
} SSMPolicyType;
|
||||
|
||||
/* These are the localized strings that PSM can feed back to
|
||||
* the plug-in. These will initially be used by the plug-in for
|
||||
* JavaScript purposes to pop up alert/confirm dialogs that would
|
||||
* cause nightmares to do if we sent UI events.
|
||||
*/
|
||||
typedef enum {
|
||||
SSM_STRING_BAD_PK11_LIB_PARAM,
|
||||
SSM_STRING_BAD_PK11_LIB_PATH,
|
||||
SSM_STRING_ADD_MOD_SUCCESS,
|
||||
SSM_STRING_DUP_MOD_FAILURE,
|
||||
SSM_STRING_ADD_MOD_FAILURE,
|
||||
SSM_STRING_BAD_MOD_NAME,
|
||||
SSM_STRING_EXT_MOD_DEL,
|
||||
SSM_STRING_INT_MOD_DEL,
|
||||
SSM_STRING_MOD_DEL_FAIL,
|
||||
SSM_STRING_ADD_MOD_WARN,
|
||||
SSM_STRING_MOD_PROMPT,
|
||||
SSM_STRING_DLL_PROMPT,
|
||||
SSM_STRING_DEL_MOD_WARN,
|
||||
SSM_STRING_INVALID_CRL,
|
||||
SSM_STRING_INVALID_CKL,
|
||||
SSM_STRING_ROOT_CKL_CERT_NOT_FOUND,
|
||||
SSM_STRING_BAD_CRL_SIGNATURE,
|
||||
SSM_STRING_BAD_CKL_SIGNATURE,
|
||||
SSM_STRING_ERR_ADD_CRL,
|
||||
SSM_STRING_ERR_ADD_CKL,
|
||||
SSM_STRING_JAVASCRIPT_DISABLED
|
||||
} SSMLocalizedString;
|
||||
|
||||
/* Event types */
|
||||
typedef enum
|
||||
{
|
||||
SSM_UI_EVENT = 0x00001000,
|
||||
SSM_TASK_COMPLETED_EVENT = 0x00002000,
|
||||
SSM_FILE_PATH_EVENT = 0x00003000,
|
||||
SSM_PROMPT_EVENT = 0x00004000,
|
||||
SSM_AUTH_EVENT = 0x00007000,
|
||||
SSM_SAVE_PREF_EVENT = 0x00008000,
|
||||
SSM_MISC_EVENT = 0x0000f000
|
||||
} SSMEventType;
|
||||
|
||||
/* Flags used in Create SSL Data request */
|
||||
typedef enum
|
||||
{
|
||||
SSM_REQUEST_SSL_DATA_SSL = 0x00000001,
|
||||
SSM_REQUEST_SSL_DATA_PROXY = 0x00000002,
|
||||
SSM_REQUEST_SSL_CONNECTION_MASK = 0x00000003
|
||||
} SSMSSLConnectionRequestType;
|
||||
|
||||
/*
|
||||
* This string is version that can be used to assemble any
|
||||
* version information by the apllication using the protocol
|
||||
* library.
|
||||
*/
|
||||
extern char SSMVersionString[];
|
||||
|
||||
/* What type of client */
|
||||
typedef enum
|
||||
{
|
||||
SSM_NOINFO,
|
||||
SSM_COMPOSE,
|
||||
SSM_MAIL_MESSAGE,
|
||||
SSM_NEWS_MESSAGE,
|
||||
SSM_SNEWS_MESSAGE,
|
||||
SSM_BROWSER
|
||||
} SSMClientType;
|
||||
|
||||
#endif /* __SSMDEFS_H__ */
|
|
@ -0,0 +1,597 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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 "stddef.h"
|
||||
#include "messages.h"
|
||||
|
||||
CMTMessageTemplate SingleNumMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SingleNumMessage, value) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SingleStringMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(SingleStringMessage, string) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SingleItemMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SingleItemMessage, item) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HelloRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HelloRequest, version) },
|
||||
{ CMT_DT_INT, offsetof(HelloRequest, policy) },
|
||||
{ CMT_DT_BOOL, offsetof(HelloRequest, doesUI) },
|
||||
{ CMT_DT_STRING, offsetof(HelloRequest, profile) },
|
||||
{ CMT_DT_STRING, offsetof(HelloRequest, profileDir) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HelloReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HelloReply, result) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, sessionID) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, version) },
|
||||
{ CMT_DT_STRING, offsetof(HelloReply, stringVersion) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, httpPort) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, policy) },
|
||||
{ CMT_DT_ITEM, offsetof(HelloReply, nonce) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SSLDataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SSLDataConnectionRequest, flags) },
|
||||
{ CMT_DT_INT, offsetof(SSLDataConnectionRequest, port) },
|
||||
{ CMT_DT_STRING, offsetof(SSLDataConnectionRequest, hostIP) },
|
||||
{ CMT_DT_STRING, offsetof(SSLDataConnectionRequest, hostName) },
|
||||
{ CMT_DT_BOOL, offsetof(SSLDataConnectionRequest, forceHandshake) },
|
||||
{ CMT_DT_ITEM, offsetof(SSLDataConnectionRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TLSDataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TLSDataConnectionRequest, port) },
|
||||
{ CMT_DT_STRING, offsetof(TLSDataConnectionRequest, hostIP) },
|
||||
{ CMT_DT_STRING, offsetof(TLSDataConnectionRequest, hostName) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TLSStepUpRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TLSStepUpRequest, connID) },
|
||||
{ CMT_DT_ITEM, offsetof(TLSStepUpRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate ProxyStepUpRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(ProxyStepUpRequest, connID) },
|
||||
{ CMT_DT_ITEM, offsetof(ProxyStepUpRequest, clientContext) },
|
||||
{ CMT_DT_STRING, offsetof(ProxyStepUpRequest, url) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PKCS7DataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PKCS7DataConnectionRequest, resID) },
|
||||
{ CMT_DT_ITEM, offsetof(PKCS7DataConnectionRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DataConnectionReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, result) },
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, connID) },
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, port) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UIEventTemplate[] =
|
||||
{
|
||||
{ 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) },
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, numTasks) },
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, result) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate VerifyDetachedSigRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, pkcs7ContentID) },
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, certUsage) },
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, hashAlgID) },
|
||||
{ CMT_DT_BOOL, offsetof(VerifyDetachedSigRequest, keepCert) },
|
||||
{ CMT_DT_ITEM, offsetof(VerifyDetachedSigRequest, hash) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateSignedRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, scertRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, ecertRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, dig_alg) },
|
||||
{ CMT_DT_ITEM, offsetof(CreateSignedRequest, digest) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateContentInfoReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, ciRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, result) },
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, errorCode) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateEncryptedRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateEncryptedRequest, scertRID) },
|
||||
{ CMT_DT_LIST, offsetof(CreateEncryptedRequest, nrcerts) },
|
||||
{ CMT_DT_INT, offsetof(CreateEncryptedRequest, rcertRIDs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateResourceRequest, type) },
|
||||
{ CMT_DT_ITEM, offsetof(CreateResourceRequest, params) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateResourceReply, result) },
|
||||
{ CMT_DT_INT, offsetof(CreateResourceReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetAttribRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetAttribRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(GetAttribRequest, fieldID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetAttribReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetAttribReply, result) },
|
||||
{ CMT_DT_CHOICE, offsetof(GetAttribReply, value.type) },
|
||||
{ CMT_DT_RID, offsetof(GetAttribReply, value.u.rid), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_INT, offsetof(GetAttribReply, value.u.numeric), 0,
|
||||
SSM_NUMERIC_ATTRIBUTE },
|
||||
{ CMT_DT_ITEM, offsetof(GetAttribReply, value.u.string), 0,
|
||||
SSM_STRING_ATTRIBUTE},
|
||||
{ CMT_DT_END_CHOICE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SetAttribRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, fieldID) },
|
||||
{ CMT_DT_CHOICE, offsetof(SetAttribRequest, value.type) },
|
||||
{ CMT_DT_RID, offsetof(SetAttribRequest, value.u.rid), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, value.u.numeric), 0,
|
||||
SSM_NUMERIC_ATTRIBUTE },
|
||||
{ CMT_DT_ITEM, offsetof(SetAttribRequest, value.u.string), 0,
|
||||
SSM_STRING_ATTRIBUTE},
|
||||
{ CMT_DT_END_CHOICE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PickleResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PickleResourceReply, result) },
|
||||
{ CMT_DT_ITEM, offsetof(PickleResourceReply, blob) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UnpickleResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceRequest, resourceType) },
|
||||
{ CMT_DT_ITEM, offsetof(UnpickleResourceRequest, resourceData) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UnpickleResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceReply, result) },
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PickleSecurityStatusReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PickleSecurityStatusReply, result) },
|
||||
{ CMT_DT_INT, offsetof(PickleSecurityStatusReply, securityLevel) },
|
||||
{ CMT_DT_ITEM, offsetof(PickleSecurityStatusReply, blob) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DupResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DupResourceReply, result) },
|
||||
{ CMT_DT_RID, offsetof(DupResourceReply, resID), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DestroyResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DestroyResourceRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(DestroyResourceRequest, resType) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate VerifyCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(VerifyCertRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(VerifyCertRequest, certUsage) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate AddTempCertToDBRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(AddTempCertToDBRequest, nickname) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, sslFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, emailFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, objSignFlags) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate MatchUserCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(MatchUserCertRequest, certType) },
|
||||
{ CMT_DT_LIST, offsetof(MatchUserCertRequest, numCANames) },
|
||||
{ CMT_DT_STRING, offsetof(MatchUserCertRequest, caNames) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate MatchUserCertReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(MatchUserCertReply, numCerts) },
|
||||
{ CMT_DT_INT, offsetof(MatchUserCertReply, certs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate EncodeCRMFReqRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(EncodeCRMFReqRequest, numRequests) },
|
||||
{ CMT_DT_INT, offsetof(EncodeCRMFReqRequest, reqIDs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CMMFCertResponseRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(CMMFCertResponseRequest, nickname) },
|
||||
{ CMT_DT_STRING, offsetof(CMMFCertResponseRequest, base64Der) },
|
||||
{ CMT_DT_INT, offsetof(CMMFCertResponseRequest, doBackup) },
|
||||
{ CMT_DT_ITEM, offsetof(CMMFCertResponseRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordRequest, tokenKey) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordRequest, prompt) },
|
||||
{ CMT_DT_ITEM, offsetof(PasswordRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordReply, result) },
|
||||
{ CMT_DT_INT, offsetof(PasswordReply, tokenID) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordReply, passwd) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate KeyPairGenRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, keyGenCtxtID) },
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, genMechanism) },
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, keySize) },
|
||||
{ CMT_DT_ITEM, offsetof(KeyPairGenRequest, params) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecodeAndCreateTempCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DecodeAndCreateTempCertRequest, type) },
|
||||
{ CMT_DT_ITEM, offsetof(DecodeAndCreateTempCertRequest, cert) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, choiceString) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, challenge) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, typeString) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, pqgString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleTokenRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStyleTokenRequest, rid) },
|
||||
{ CMT_DT_LIST, offsetof(GenKeyOldStyleTokenRequest, numtokens) },
|
||||
{ CMT_DT_STRING,offsetof(GenKeyOldStyleTokenRequest, tokenNames)},
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleTokenReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStyleTokenReply, rid) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStyleTokenReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleTokenReply, tokenName) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStylePasswordRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, rid) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStylePasswordRequest, tokenName) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStylePasswordRequest, internal) },
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, minpwdlen) },
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, maxpwdlen) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStylePasswordReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordReply, rid) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStylePasswordReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStylePasswordReply, password) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
|
||||
CMTMessageTemplate GetKeyChoiceListRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListRequest, type) },
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListRequest, pqgString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetKeyChoiceListReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(GetKeyChoiceListReply, nchoices) },
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListReply, choices) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate AddNewSecurityModuleRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(AddNewSecurityModuleRequest, moduleName) },
|
||||
{ CMT_DT_STRING, offsetof(AddNewSecurityModuleRequest, libraryPath) },
|
||||
{ CMT_DT_INT, offsetof(AddNewSecurityModuleRequest, pubMechFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddNewSecurityModuleRequest, pubCipherFlags) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate FilePathRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(FilePathRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathRequest, prompt) },
|
||||
{ CMT_DT_BOOL, offsetof(FilePathRequest, getExistingFile) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathRequest, fileRegEx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate FilePathReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(FilePathReply, resID) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathReply, filePath) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordPromptReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordPromptReply, resID) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordPromptReply, promptReply) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SignTextRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SignTextRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, stringToSign) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, hostName) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, caOption) },
|
||||
{ CMT_DT_LIST, offsetof(SignTextRequest, numCAs) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, caNames) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetLocalizedTextReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetLocalizedTextReply, whichString) },
|
||||
{ CMT_DT_STRING, offsetof(GetLocalizedTextReply, localizedString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate ImportCertReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(ImportCertReply, result) },
|
||||
{ CMT_DT_INT, offsetof(ImportCertReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PromptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PromptRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(PromptRequest, prompt) },
|
||||
{ CMT_DT_ITEM, offsetof(PromptRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PromptReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PromptReply, resID) },
|
||||
{ CMT_DT_BOOL, offsetof(PromptReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(PromptReply, promptReply) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate RedirectCompareRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(RedirectCompareRequest, socketStatus1Data) },
|
||||
{ CMT_DT_ITEM, offsetof(RedirectCompareRequest, socketStatus2Data) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecodeAndAddCRLRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(DecodeAndAddCRLRequest, derCrl) },
|
||||
{ CMT_DT_INT, offsetof(DecodeAndAddCRLRequest, type) },
|
||||
{ CMT_DT_STRING, offsetof(DecodeAndAddCRLRequest, url) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SecurityAdvisorRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, infoContext) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, hostname) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, senderAddr) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, encryptedP7CInfo) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, signedP7CInfo) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, decodeError) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, verifyError) },
|
||||
{ CMT_DT_BOOL, offsetof(SecurityAdvisorRequest, encryptthis) },
|
||||
{ CMT_DT_BOOL, offsetof(SecurityAdvisorRequest, signthis) },
|
||||
{ CMT_DT_LIST, offsetof(SecurityAdvisorRequest, numRecipients) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, recipients) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCAddTempCertToPermDBRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SCAddTempCertToPermDBRequest, certKey) },
|
||||
{ CMT_DT_STRING, offsetof(SCAddTempCertToPermDBRequest, trustStr) },
|
||||
{ CMT_DT_STRING, offsetof(SCAddTempCertToPermDBRequest, nickname) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCDeletePermCertsRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SCDeletePermCertsRequest, certKey) },
|
||||
{ CMT_DT_BOOL, offsetof(SCDeletePermCertsRequest, deleteAll) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TimeMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, year) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, month) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, day) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, hour) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, minute) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, second) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCCertIndexEnumReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SCCertIndexEnumReply, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(SCCertIndexEnumReply, list) },
|
||||
{ CMT_DT_STRING, offsetof(CertEnumElement, name) },
|
||||
{ CMT_DT_ITEM, offsetof(CertEnumElement, certKey) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/* Test template */
|
||||
|
||||
CMTMessageTemplate TestListTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(TestList, listName) },
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(TestList, numElements) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(TestList, elements) },
|
||||
{ CMT_DT_STRING, offsetof(TestListElement, name) },
|
||||
{ CMT_DT_STRING, offsetof(TestListElement, value) },
|
||||
{ CMT_DT_END_STRUCT_LIST},
|
||||
{ CMT_DT_END}
|
||||
};
|
||||
|
||||
CMTMessageTemplate SetPrefListMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(SetPrefListMessage, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(SetPrefListMessage, list) },
|
||||
{ CMT_DT_STRING, offsetof(SetPrefElement, key) },
|
||||
{ CMT_DT_STRING, offsetof(SetPrefElement, value) },
|
||||
{ CMT_DT_INT, offsetof(SetPrefElement, type) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetPrefListRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(GetPrefListRequest, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(GetPrefListRequest, list) },
|
||||
{ CMT_DT_STRING, offsetof(GetPrefElement, key) },
|
||||
{ CMT_DT_INT, offsetof(GetPrefElement, type) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetCertExtensionTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetCertExtension, resID) },
|
||||
{ CMT_DT_INT, offsetof(GetCertExtension, extension) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HTMLCertInfoRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, certID) },
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, showImages) },
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, showIssuer) },
|
||||
{ CMT_DT_END }
|
||||
};
|
Загрузка…
Ссылка в новой задаче