Compare commits
5 Commits
PARTYTOOL1
...
sdr_1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4127f7ed92 | ||
|
|
fc8cd8ebd2 | ||
|
|
26ed09faf4 | ||
|
|
14e542e142 | ||
|
|
fe9b32e930 |
74
mozilla/security/psm/lib/Makefile
Executable file
74
mozilla/security/psm/lib/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! 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). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
32
mozilla/security/psm/lib/Makefile.in
Normal file
32
mozilla/security/psm/lib/Makefile.in
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = protocol client
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
3
mozilla/security/psm/lib/client/MANIFEST
Normal file
3
mozilla/security/psm/lib/client/MANIFEST
Normal file
@@ -0,0 +1,3 @@
|
||||
cmtclist.h
|
||||
cmtcmn.h
|
||||
cmtjs.h
|
||||
74
mozilla/security/psm/lib/client/Makefile
Executable file
74
mozilla/security/psm/lib/client/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! 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). #
|
||||
#######################################################################
|
||||
include config.mk
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
70
mozilla/security/psm/lib/client/Makefile.in
Normal file
70
mozilla/security/psm/lib/client/Makefile.in
Normal file
@@ -0,0 +1,70 @@
|
||||
#! 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 \
|
||||
cmtsdr.c \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lprotocol
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
99
mozilla/security/psm/lib/client/cmtadvisor.c
Normal file
99
mozilla/security/psm/lib/client/cmtadvisor.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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"
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1362
mozilla/security/psm/lib/client/cmtcert.c
Normal file
1362
mozilla/security/psm/lib/client/cmtcert.c
Normal file
File diff suppressed because it is too large
Load Diff
111
mozilla/security/psm/lib/client/cmtclist.h
Normal file
111
mozilla/security/psm/lib/client/cmtclist.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 cmtclist_h___
|
||||
#define cmtclist_h___
|
||||
|
||||
typedef struct CMTCListStr CMTCList;
|
||||
/*
|
||||
** Circular linked list
|
||||
*/
|
||||
struct CMTCListStr {
|
||||
CMTCList *next;
|
||||
CMTCList *prev;
|
||||
};
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, before "_l".
|
||||
*/
|
||||
#define CMT_INSERT_BEFORE(_e,_l) \
|
||||
(_e)->next = (_l); \
|
||||
(_e)->prev = (_l)->prev; \
|
||||
(_l)->prev->next = (_e); \
|
||||
(_l)->prev = (_e); \
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, after "_l".
|
||||
*/
|
||||
#define CMT_INSERT_AFTER(_e,_l) \
|
||||
(_e)->next = (_l)->next; \
|
||||
(_e)->prev = (_l); \
|
||||
(_l)->next->prev = (_e); \
|
||||
(_l)->next = (_e); \
|
||||
|
||||
/*
|
||||
** Append an element "_e" to the end of the list "_l"
|
||||
*/
|
||||
#define CMT_APPEND_LINK(_e,_l) CMT_INSERT_BEFORE(_e,_l)
|
||||
|
||||
/*
|
||||
** Insert an element "_e" at the head of the list "_l"
|
||||
*/
|
||||
#define CMT_INSERT_LINK(_e,_l) CMT_INSERT_AFTER(_e,_l)
|
||||
|
||||
/* Return the head/tail of the list */
|
||||
#define CMT_LIST_HEAD(_l) (_l)->next
|
||||
#define CMT_LIST_TAIL(_l) (_l)->prev
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list.
|
||||
*/
|
||||
#define CMT_REMOVE_LINK(_e) \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list. Also initializes the
|
||||
** linkage.
|
||||
*/
|
||||
#define CMT_REMOVE_AND_INIT_LINK(_e) \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
(_e)->next = (_e); \
|
||||
(_e)->prev = (_e); \
|
||||
|
||||
/*
|
||||
** Return non-zero if the given circular list "_l" is empty, zero if the
|
||||
** circular list is not empty
|
||||
*/
|
||||
#define CMT_CLIST_IS_EMPTY(_l) \
|
||||
((_l)->next == (_l))
|
||||
|
||||
/*
|
||||
** Initialize a circular list
|
||||
*/
|
||||
#define CMT_INIT_CLIST(_l) \
|
||||
(_l)->next = (_l); \
|
||||
(_l)->prev = (_l); \
|
||||
|
||||
#define CMT_INIT_STATIC_CLIST(_l) \
|
||||
{(_l), (_l)}
|
||||
|
||||
#endif /* cmtclist_h___ */
|
||||
2264
mozilla/security/psm/lib/client/cmtcmn.h
Normal file
2264
mozilla/security/psm/lib/client/cmtcmn.h
Normal file
File diff suppressed because it is too large
Load Diff
480
mozilla/security/psm/lib/client/cmtevent.c
Normal file
480
mozilla/security/psm/lib/client/cmtevent.c
Normal file
@@ -0,0 +1,480 @@
|
||||
/* -*- 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, NULL, 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, NULL, 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, NULL, 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;
|
||||
CMTItem msgCopy;
|
||||
|
||||
/* Init the msgCopy */
|
||||
msgCopy.data = 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Copy the message to allow a second try with the old format */
|
||||
msgCopy.len = eventData->len;
|
||||
msgCopy.data = calloc(msgCopy.len, 1);
|
||||
if (msgCopy.data) {
|
||||
memcpy(msgCopy.data, eventData->data, eventData->len);
|
||||
}
|
||||
|
||||
/* Get the event data first */
|
||||
if (CMT_DecodeMessage(UIEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
/* Attempt to decode using the old format. Modal is True */
|
||||
if (!msgCopy.data ||
|
||||
CMT_DecodeMessage(OldUIEventTemplate, &event, &msgCopy) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set default modal value */
|
||||
event.isModal = CM_TRUE;
|
||||
}
|
||||
|
||||
/* Convert the client context to a pointer */
|
||||
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.isModal, 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);
|
||||
free(msgCopy.data);
|
||||
return;
|
||||
}
|
||||
|
||||
216
mozilla/security/psm/lib/client/cmthash.c
Normal file
216
mozilla/security/psm/lib/client/cmthash.c
Normal file
@@ -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, NULL, 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;
|
||||
}
|
||||
56
mozilla/security/psm/lib/client/cmtimpl.h
Normal file
56
mozilla/security/psm/lib/client/cmtimpl.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 __CMTIMPL_H_
|
||||
#define __CMTIMPL_H_
|
||||
|
||||
typedef unsigned long CMT_HANDLE;
|
||||
|
||||
struct _CMTControl {
|
||||
CMT_HANDLE channelID;
|
||||
int socketID;
|
||||
CMTStatus (* cmtEventCallback)(struct _CMTControl * control,
|
||||
CMTItem * event, void * arg);
|
||||
void * cmtEventCallbackArg;
|
||||
struct _CMTData * cmtDataConnection;
|
||||
} _CMTControl;
|
||||
|
||||
|
||||
|
||||
struct _CMTData {
|
||||
CMT_HANDLE channelID;
|
||||
int socketID;
|
||||
struct _CMTData * next;
|
||||
struct _CMTData * previous;
|
||||
};
|
||||
|
||||
#endif /*__CMTIMPL_H_*/
|
||||
484
mozilla/security/psm/lib/client/cmtinit.c
Normal file
484
mozilla/security/psm/lib/client/cmtinit.c
Normal file
@@ -0,0 +1,484 @@
|
||||
/* -*- 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/stat.h>
|
||||
#include <netinet/tcp.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include <Events.h> // for WaitNextEvent
|
||||
#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 <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
|
||||
|
||||
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 = NULL;
|
||||
size_t stringLen;
|
||||
|
||||
/* On the Mac, we do special magic in the Seamonkey PSM component, so
|
||||
if PSM isn't launched by the time we reach this point, we're not doing well. */
|
||||
#ifndef XP_MAC
|
||||
|
||||
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);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
#elif defined(XP_MAC)
|
||||
for (i=0; i<30; i++)
|
||||
{
|
||||
EventRecord theEvent;
|
||||
WaitNextEvent(0, &theEvent, 30, NULL);
|
||||
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;
|
||||
#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");
|
||||
|
||||
/* fill in the CMTControl struct */
|
||||
control = (PCMT_CONTROL)calloc(sizeof(CMT_CONTROL), 1);
|
||||
if (control == NULL ) {
|
||||
goto loser;
|
||||
}
|
||||
control->sock = sock;
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
556
mozilla/security/psm/lib/client/cmtjs.c
Normal file
556
mozilla/security/psm/lib/client/cmtjs.c
Normal file
@@ -0,0 +1,556 @@
|
||||
/*
|
||||
* 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 "cmtutils.h"
|
||||
#include "cmtjs.h"
|
||||
#include "messages.h"
|
||||
|
||||
CMTStatus
|
||||
CMT_GenerateKeyPair(PCMT_CONTROL control, CMUint32 keyGenContext,
|
||||
CMUint32 mechType, CMTItem *param, CMUint32 keySize,
|
||||
CMUint32 *keyPairId)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
KeyPairGenRequest request = {0, 0, 0, {0, NULL, 0}};
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.keyGenCtxtID = keyGenContext;
|
||||
request.genMechanism = mechType;
|
||||
if (param) {
|
||||
request.params = *param;
|
||||
}
|
||||
request.keySize = keySize;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(KeyPairGenRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_CREATE_KEY_PAIR;
|
||||
|
||||
/* Send the message and get the response */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_CREATE_KEY_PAIR)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*keyPairId = reply.value;
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
*keyPairId = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus
|
||||
CMT_CreateNewCRMFRequest(PCMT_CONTROL control, CMUint32 keyPairID,
|
||||
SSMKeyGenType keyGenType, CMUint32 *reqID)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.value = keyPairID;
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION |
|
||||
SSM_CREATE_CRMF_REQ;
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_CREATE_CRMF_REQ)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*reqID = reply.value;
|
||||
|
||||
rv = CMT_SetNumericAttribute(control, *reqID, SSM_FID_CRMFREQ_KEY_TYPE,
|
||||
keyGenType);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_EncodeCRMFRequest(PCMT_CONTROL control, CMUint32 *crmfReqID,
|
||||
CMUint32 numRequests, char ** der)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
EncodeCRMFReqRequest request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.numRequests = numRequests;
|
||||
request.reqIDs = (long *) crmfReqID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(EncodeCRMFReqRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_DER_ENCODE_REQ;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_DER_ENCODE_REQ)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* XXX Should this be a string? Decode the message */
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*der = (char *) reply.item.data;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_ProcessCMMFResponse(PCMT_CONTROL control, char *nickname,
|
||||
char *certRepString, CMBool doBackup,
|
||||
void *clientContext)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMMFCertResponseRequest request;
|
||||
|
||||
if(!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.nickname = nickname;
|
||||
request.base64Der = certRepString;
|
||||
request.doBackup = doBackup;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CMMFCertResponseRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_PROCESS_CMMF_RESP;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_PROCESS_CMMF_RESP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_CreateResource(PCMT_CONTROL control, SSMResourceType resType,
|
||||
CMTItem *params, CMUint32 *rsrcId, CMUint32 *errorCode)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CreateResourceRequest request = {0, {0, NULL, 0}};
|
||||
CreateResourceReply reply;
|
||||
|
||||
request.type = resType;
|
||||
if (params) {
|
||||
request.params = *params;
|
||||
}
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CREATE_RESOURCE;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CREATE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(CreateResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*rsrcId = reply.resID;
|
||||
*errorCode = reply.result;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_SignText(PCMT_CONTROL control, CMUint32 resID, char* stringToSign, char* hostName, char* caOption, CMInt32 numCAs, char** caNames)
|
||||
{
|
||||
CMTItem message;
|
||||
SignTextRequest request;
|
||||
|
||||
|
||||
/* So some basic parameter checking */
|
||||
if (!control || !stringToSign) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resID;
|
||||
request.stringToSign = stringToSign;
|
||||
request.hostName = hostName;
|
||||
request.caOption = caOption;
|
||||
request.numCAs = numCAs;
|
||||
request.caNames = caNames;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(SignTextRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_FORMSIGN_ACTION | SSM_SIGN_TEXT;
|
||||
|
||||
/* 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_FORMSIGN_ACTION | SSM_SIGN_TEXT)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_ProcessChallengeResponse(PCMT_CONTROL control, char *challengeString,
|
||||
char **responseString)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleStringMessage request;
|
||||
SingleStringMessage reply;
|
||||
|
||||
/* Set the request */
|
||||
request.string = challengeString;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleStringMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_CHALLENGE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_CHALLENGE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleStringMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*responseString = reply.string;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_FinishGeneratingKeys(PCMT_CONTROL control, CMUint32 keyGenContext)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
|
||||
/* Set up the request */
|
||||
request.value = keyGenContext;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_FINISH_KEY_GEN;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the reply */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_FINISH_KEY_GEN)) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_GetLocalizedString(PCMT_CONTROL control,
|
||||
SSMLocalizedString whichString,
|
||||
char **localizedString)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
GetLocalizedTextReply reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.value = whichString;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_LOCALIZED_TEXT;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_LOCALIZED_TEXT)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetLocalizedTextReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (reply.whichString != whichString) {
|
||||
goto loser;
|
||||
}
|
||||
*localizedString = reply.localizedString;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
*localizedString = NULL;
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_AddNewModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
char *libraryPath,
|
||||
unsigned long pubMechFlags,
|
||||
unsigned long pubCipherFlags)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
AddNewSecurityModuleRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.moduleName = moduleName;
|
||||
request.libraryPath = libraryPath;
|
||||
request.pubMechFlags = pubMechFlags;
|
||||
request.pubCipherFlags = pubCipherFlags;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(AddNewSecurityModuleRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_ADD_NEW_MODULE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_ADD_NEW_MODULE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the response */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_DeleteModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
int *moduleType)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleStringMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.string = moduleName;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleStringMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_DEL_MODULE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_DEL_MODULE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*moduleType = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_LogoutAllTokens(PCMT_CONTROL control)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_LOGOUT_ALL;
|
||||
message.data = NULL;
|
||||
message.len = 0;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
return rv;
|
||||
}
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_LOGOUT_ALL)) {
|
||||
return CMTFailure;
|
||||
}
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLCapabilities(PCMT_CONTROL control, CMInt32 *capabilites)
|
||||
{
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
|
||||
message.type = (SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_ENABLED_CIPHERS);
|
||||
message.data = NULL;
|
||||
message.len = 0;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_ENABLED_CIPHERS)) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply,
|
||||
&message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*capabilites = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
555
mozilla/security/psm/lib/client/cmtjs.h
Normal file
555
mozilla/security/psm/lib/client/cmtjs.h
Normal file
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
* 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 _CMTJS_H_
|
||||
#define _CMTJS_H_
|
||||
#include "cmtcmn.h"
|
||||
#include "ssmdefs.h"
|
||||
#include "rsrcids.h"
|
||||
/*
|
||||
* Define some constants.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These defines are used in conjuction with the function
|
||||
* CMT_AddNewModule.
|
||||
*/
|
||||
#define PUBLIC_MECH_RSA_FLAG 0x00000001ul
|
||||
#define PUBLIC_MECH_DSA_FLAG 0x00000002ul
|
||||
#define PUBLIC_MECH_RC2_FLAG 0x00000004ul
|
||||
#define PUBLIC_MECH_RC4_FLAG 0x00000008ul
|
||||
#define PUBLIC_MECH_DES_FLAG 0x00000010ul
|
||||
#define PUBLIC_MECH_DH_FLAG 0x00000020ul
|
||||
#define PUBLIC_MECH_FORTEZZA_FLAG 0x00000040ul
|
||||
#define PUBLIC_MECH_RC5_FLAG 0x00000080ul
|
||||
#define PUBLIC_MECH_SHA1_FLAG 0x00000100ul
|
||||
#define PUBLIC_MECH_MD5_FLAG 0x00000200ul
|
||||
#define PUBLIC_MECH_MD2_FLAG 0x00000400ul
|
||||
|
||||
#define PUBLIC_MECH_RANDOM_FLAG 0x08000000ul
|
||||
#define PUBLIC_MECH_FRIENDLY_FLAG 0x10000000ul
|
||||
#define PUBLIC_OWN_PW_DEFAULTS 0X20000000ul
|
||||
#define PUBLIC_DISABLE_FLAG 0x40000000ul
|
||||
|
||||
|
||||
/*
|
||||
* This is the lone supported constant for the Cipher flag
|
||||
* for CMT_AddNewModule
|
||||
*/
|
||||
#define PUBLIC_CIPHER_FORTEZZA_FLAG 0x00000001ul
|
||||
|
||||
CMT_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_GenerateKeyPair
|
||||
* -----------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyGenContext
|
||||
* The Resource ID of a key gen context to use for creating the
|
||||
* key pair.
|
||||
* mechType
|
||||
* A PKCS11 mechanism used to generate the key pair. Valid values are:
|
||||
* CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000
|
||||
* CKM_DSA_KEY_PAIR_GEN 0x00000010
|
||||
* The definition of these values can be found at
|
||||
* http://www.rsa.com/rsalabs/pubs/pkcs11.html
|
||||
* The psm module currently supports v2.01 of PKCS11
|
||||
* params
|
||||
* This parameter will be used to pass parameters to the Key Pair
|
||||
* generation process. Currently this feature is not supported, so
|
||||
* pass in NULL for this parameter.
|
||||
* keySize
|
||||
* The size (in bits) of the key to generate.
|
||||
* keyPairId
|
||||
* A pointer to pre-allocated memory where the function can place
|
||||
* the value of the resource ID of the key pair that gets created.
|
||||
*
|
||||
* NOTES:
|
||||
* This function will send a message to the psm server requesting that
|
||||
* a public/private key pair be generated. The key gen context will queue
|
||||
* the request. You can send as many key gen requests as you want with a
|
||||
* given key gen context. After sending all the key gen requests, the user
|
||||
* must call CMT_FinishGeneratingKeys so that the key gen context actually
|
||||
* generates the keys.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the request for key generation
|
||||
* was queued successfully and the corresponding resource ID can be found
|
||||
* at *keyPairId. Any other return value indicates an error and the value
|
||||
* at *keyPairId should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_GenerateKeyPair(PCMT_CONTROL control, CMUint32 keyGenContext,
|
||||
CMUint32 mechType, CMTItem *params, CMUint32 keySize,
|
||||
CMUint32 *keyPairId);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_FinishGeneratingKeys
|
||||
* ----------------------------------
|
||||
* INPUTS
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyGenContext
|
||||
* The resource ID of the key gen context which should finish
|
||||
* generating its key pairs.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server notifying the key
|
||||
* gen context with the resource ID of keyGenContext to finish generating
|
||||
* all of the key gen requests it has queued up. After each key gen has
|
||||
* finished, the psm server will send a SSM_TASK_COMPLETED_EVENT. So in order
|
||||
* to detect when all of the key gens are done, the user should register
|
||||
* an event handler. See comments for CMT_RegisterEventHandler for information
|
||||
* on how to successfully register event handler callbacks. You must register
|
||||
* the event handler with keyGenContext as the target resource ID for this
|
||||
* to work correctly.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the key gen context has started to
|
||||
* generate the key pairs in its queue. Any other return value indicates an
|
||||
* error and the key pairs will not be generated.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_FinishGeneratingKeys(PCMT_CONTROL control, CMUint32 keyGenContext);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_CreateNewCRMFRequest
|
||||
* ----------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyPairID
|
||||
* The resource ID of the key pair that should be associated with
|
||||
* the CRMF request created. At the time this function is called,
|
||||
* key pair should have already been created.
|
||||
* keyGenType
|
||||
* An enumeration that explains how the key pair will be used.
|
||||
* Look at the definition of SSMKeyGenType in ssmdefs.h for valid
|
||||
* values and their affects on the request.
|
||||
* reqID
|
||||
* A pointer to a pre-allocatd chunk of memory where the library
|
||||
* can place the resource ID of the new CRMF request.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server requesting that a new
|
||||
* CRMF resource object be created. Each CRMF request must be associated with
|
||||
* a public/private key pair, that is why the keyPairID parameter exists.
|
||||
* The keyGenType parameter is used to initialize the request, eg set the
|
||||
* correct keyUsage extension.
|
||||
*
|
||||
* Before encoding a CRMF request, the user will want to set the appropriate
|
||||
* attributes to build up the request. The supported attributes are:
|
||||
*
|
||||
* Attribute Enumeration Attribute Type What value means
|
||||
* --------------------- -------------- ----------------
|
||||
* SSM_FID_CRMFREQ_REGTOKEN String The value to encode as
|
||||
* the registration token
|
||||
* value for the request.
|
||||
*
|
||||
* SSM_FID_CRMFREQ_AUTHENTICATOR String The value to encode as
|
||||
* authenticator control
|
||||
* in the request.
|
||||
*
|
||||
* SSM_FID_DN String The RFC1485 formatted
|
||||
* DN to include in the
|
||||
* CRMF request.
|
||||
*
|
||||
* For information on how to properly set the attribute of a resource, refer
|
||||
* to the comments for the functions CMT_SetNumericAttribute and
|
||||
* CMT_SetStringAttribute.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates a new CRMF resource was created by
|
||||
* the psm server and has the resource ID placed at *reqID. Any other return
|
||||
* value indicates an error and the value at *reqID should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_CreateNewCRMFRequest(PCMT_CONTROL control, CMUint32 keyPairID,
|
||||
SSMKeyGenType keyGenType, CMUint32 *reqID);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_EncodeCRMFRequest
|
||||
* ------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* crmfReqID
|
||||
* An array of resource ID's for CRMF objects to be encoded.
|
||||
* numRequests
|
||||
* The length of the array crmfReqID that is passed in.
|
||||
* der
|
||||
* A pointer to a pre-allocated pointer for a char* where the library
|
||||
* can place the final DER-encoding of the requests.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server requesting that
|
||||
* a number of CRMF requests be encoded into their appropriate DER
|
||||
* representation. The DER that is sent back will be of the type
|
||||
* CertReqMessages as define in the internet draft for CRMF. To look at the
|
||||
* draft, visit the following URL:
|
||||
* http://search.ietf.org/internet-drafts/internet-draft-ietf-pkix-crmf-01.txt
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates psm successfully encoded the requests
|
||||
* and placed the base64 DER encoded request at *der. Any other return value
|
||||
* indicates an error and the value at *der should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_EncodeCRMFRequest(PCMT_CONTROL control, CMUint32 *crmfReqID,
|
||||
CMUint32 numRequests, char ** der);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_ProcessCMMFResponse
|
||||
* ---------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* nickname
|
||||
* The nickname that should be associated with the certificate
|
||||
* contained in the CMMF Response.
|
||||
* certRepString
|
||||
* This is the base 64 encoded CertRepContent that issues a certificate.
|
||||
* The psm server will decode the base 64 data and then parse the
|
||||
* CertRepContent.
|
||||
* doBackup
|
||||
* A boolean value indicating whether or not psm should initiate the
|
||||
* process of backing up the newly issued certificate into a PKCS-12
|
||||
* file.
|
||||
* clientContext
|
||||
* Client supplied data pointer that is returned to the client during
|
||||
* a UI event.
|
||||
* NOTES:
|
||||
* This function takes a CertRepContent as defined in the CMMF internet draft
|
||||
* (http://search.ietf.org/internet-drafts/draft-ietf-pkix-cmmf-02.txt) and
|
||||
* imports the certificate into the user's database. The certificate will have
|
||||
* the string value of nickanme as it's nickname when added to the database
|
||||
* unless another certificate with that same Distinguished Name (DN) already
|
||||
* exists in the database, in which case the nickname of the certificate that
|
||||
* already exists will be used. If the value passed in for doBackup is
|
||||
* non-zero, then the psm server will initiate the process of backing up the
|
||||
* certificate(s) that were just imported.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the certificate(s) were successfully
|
||||
* added to the database. Any other return value means the certificate(s) could
|
||||
* not be successfully added to the database.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_ProcessCMMFResponse(PCMT_CONTROL control, char *nickname,
|
||||
char *certRepString, CMBool doBackup,
|
||||
void *clientContext);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_CreateResource
|
||||
* ----------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* resType
|
||||
* The enumeration representing the resource type to create.
|
||||
* params
|
||||
* A resource dependent binary string that will be sent to the psm
|
||||
* server. Each resource will expect a binary string it defines.
|
||||
* rsrcId
|
||||
* A pointer to a pre-allocated chunk of memory where the library
|
||||
* can place the resource ID of the newly created resource.
|
||||
* errorCode
|
||||
* A pointer to a pre-allocated chunk of memory where the library
|
||||
* can place the errorCode returned by the psm server after creating
|
||||
* the resource.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server requesting that a new
|
||||
* resource be created. The params parameter depends on the type of resource
|
||||
* being created. Below is a table detailing the format of the params for
|
||||
* a given resource type. Only the resource types listed below can be created
|
||||
* by calling this function.
|
||||
*
|
||||
* Resource Type constant Value for params
|
||||
* ------------------------------ ----------------
|
||||
* SSM_RESTYPE_KEYGEN_CONTEXT NULL
|
||||
* SSM_RESTYPE_SECADVISOR_CONTEXT NULL
|
||||
* SSM_RESTYPE_SIGNTEXT NULL
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess means the psm server received the request and
|
||||
* processed the create resource create. If the value at *errorCode is zero,
|
||||
* then the value at *rsrcId is the resource ID of the newly created resource.
|
||||
* Otherwise, creating the new resource failed and *errorCode contains the
|
||||
* error code returned by the psm server. ???What are the return values and
|
||||
* what do they mean. Any other return value indicates there was an error
|
||||
* in the communication with the psm server and the values at *rsrcId and
|
||||
* *errorCode should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_CreateResource(PCMT_CONTROL control, SSMResourceType resType,
|
||||
CMTItem *params, CMUint32 *rsrcId, CMUint32 *errorCode);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_SignText
|
||||
* ----------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* resID
|
||||
* The resource ID of an SSMSignTextResource.
|
||||
* stringToSign
|
||||
* The string that the psm server should sign.
|
||||
* hostName
|
||||
* The host name of the site that is requesting a string to be
|
||||
* signed. This is used for displaying the UI that tells the user
|
||||
* a web site has requested the use sign some text.
|
||||
* caOption
|
||||
* If the value is "auto" then psm will select the certificate
|
||||
* to use for signing automatically.
|
||||
* If the value is "ask" then psm will display a list of
|
||||
* certificates for signing.
|
||||
* numCAs
|
||||
* The number of CA names included in the array caNames passed in as
|
||||
* the last parameter to this function.
|
||||
* caNames
|
||||
* An array of CA Names to use for filtering the user certs to use
|
||||
* for signing the text.
|
||||
* NOTES
|
||||
* This function will sign the text passed via the parameter stringToSign.
|
||||
* The function will also cause the psm server to send some UI notifying the
|
||||
* user that a site has requested the user sign some text. The hostName
|
||||
* parameter is used in the UI to inform the user which site is requesting
|
||||
* the signed text. The caOption is used to determine if the psm server
|
||||
* should automatically select which personal cert to use in signing the
|
||||
* text. The caNames array is ussed to narrow down the field of personal
|
||||
* certs to use when signing the text. In other words, only personal certs
|
||||
* trusted by the CA's passed in will be used.
|
||||
*
|
||||
* RETURN
|
||||
* If the function returns CMTSuccess, that indicates the psm server
|
||||
* successfully signed the text. The signed text can be retrieved by
|
||||
* calling CMT_GetStringResource and passing in SSM_FID_SIGNTEXT_RESULT
|
||||
* as the field ID. Any other return value indicates an error meaning the
|
||||
* string was not signed successfully.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_SignText(PCMT_CONTROL control, CMUint32 resID, char* stringToSign,
|
||||
char* hostName, char *caOption, CMInt32 numCAs, char** caNames);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_ProcessChallengeResponse
|
||||
* --------------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* challengeString
|
||||
* The base64 encoded Challenge string received as the
|
||||
* Proof-Of-Possession Challenge in response to CRMF request that
|
||||
* specified Challenge-Reponse as the method for Proof-Of-Possession.
|
||||
* responseString
|
||||
* A pointer to pre-allocated char* where the library can place a
|
||||
* copy of the bas64 encoded response to the challenge presented.
|
||||
* NOTES
|
||||
* This function takes the a challenge--that is encrypted with the public key
|
||||
* of a certificate we created--and decrypts it with the private key we
|
||||
* generated. The format of the challenge is as follows:
|
||||
*
|
||||
* Challenge ::= SEQUENCE {
|
||||
* owf AlgorithmIdentifier OPTIONAL,
|
||||
* -- MUST be present in the first Challenge; MAY be omitted in any
|
||||
* -- subsequent Challenge in POPODecKeyChallContent (if omitted,
|
||||
* -- then the owf used in the immediately preceding Challenge is
|
||||
* -- to be used).
|
||||
* witness OCTET STRING,
|
||||
* -- the result of applying the one-way function (owf) to a
|
||||
* -- randomly-generated INTEGER, A. [Note that a different
|
||||
* -- INTEGER MUST be used for each Challenge.]
|
||||
* sender GeneralName,
|
||||
* -- the name of the sender.
|
||||
* key OCTET STRING,
|
||||
* -- the public key used to encrypt the challenge. This will allow
|
||||
* -- the client to find the appropriate key to do the decryption.
|
||||
* challenge OCTET STRING
|
||||
* -- the encryption (under the public key for which the cert.
|
||||
* -- request is being made) of Rand, where Rand is specified as
|
||||
* -- Rand ::= SEQUENCE {
|
||||
* -- int INTEGER,
|
||||
* -- - the randomly-generated INTEGER A (above)
|
||||
* -- senderHash OCTET STRING
|
||||
* -- - the result of applying the one-way function (owf) to
|
||||
* -- - the sender's general name
|
||||
* -- }
|
||||
* -- the size of "int" must be small enough such that "Rand" can be
|
||||
* -- contained within a single PKCS #1 encryption block.
|
||||
* }
|
||||
* This challenge is based on the Challenge initially defined in the CMMF
|
||||
* internet draft, but differs in that this structure includes the sender
|
||||
* as part of the challenge along with the public key and includes a has
|
||||
* of the sender in the encrypted Rand structure. The reason for including
|
||||
* the key is to facilitate looking up the key that should be used to
|
||||
* decipher the challenge. Including the hash of the sender in the encrypted
|
||||
* Rand structure makes the challenge smaller and allows it to fit in
|
||||
* one RSA block.
|
||||
*
|
||||
* The response is of the type POPODecKeyRespContent as defined in the CMMF
|
||||
* internet draft.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates psm successfully parsed and processed
|
||||
* the challenge and created a response. The base64 encoded response to the
|
||||
* challenge is placed at *responseString. Any other return value indicates
|
||||
* an error and the value at *responseString should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_ProcessChallengeResponse(PCMT_CONTROL control, char *challengeString,
|
||||
char **responseString);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_GetLocalizedString
|
||||
* --------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* whichString
|
||||
* The enumerated value corresponding to the localized string to
|
||||
* retrieve from the psm server
|
||||
* localizedString
|
||||
* A pointer to a pre-allocated char* where the library can place
|
||||
* copy of the localized string retrieved from the psm server.
|
||||
* NOTES
|
||||
* This function retrieves a localized string from the psm server. These
|
||||
* strings are useful for strings that aren't localized in the client
|
||||
* making use of the psm server, but need to be displayed by the user. Look
|
||||
* in protocol.h for the enumerations of the localized strings that can
|
||||
* be fetched from psm via this method.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the localized string was retrieved
|
||||
* successfully and the localized value is located at *localizedString. Any
|
||||
* other return value indicates an error and the value at *localizedString
|
||||
* should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_GetLocalizedString(PCMT_CONTROL control,
|
||||
SSMLocalizedString whichString,
|
||||
char **localizedString);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_DeleteModule
|
||||
* --------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* moduleName
|
||||
* The name of the PKCS11 module to delete.
|
||||
* moduleType
|
||||
* A pointer to a pre-allocated integer where the library can place
|
||||
* a value that tells what the type of module was deleted.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server requesting the server
|
||||
* delete a PKCS-11 module stored in psm's security module database. moduleName
|
||||
* is the value passed in as moduleName when the module was added to the
|
||||
* security module database of psm.
|
||||
* The values that may be returned by psm for moduleType are:
|
||||
*
|
||||
* 0 The module was an external module developped by a third party
|
||||
* that was added to the psm security module.
|
||||
*
|
||||
* 1 The module deleted was the internal PKCS-11 module that comes
|
||||
* built in with the psm server.
|
||||
*
|
||||
* 2 The module that was deleted was the FIPS internal module.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the security module was successfully
|
||||
* delete from the psm security module database and the value at *moduleType
|
||||
* will tell what type of module was deleted.
|
||||
* Any other return value indicates an error and the value at *moduleType
|
||||
* should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_DeleteModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
int *moduleType);
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_AddNewModule
|
||||
* --------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* moduleName
|
||||
* The name to be associated with the module once it is added to
|
||||
* the psm security module database.
|
||||
* libraryPath
|
||||
* The path to the library to be loaded. The library should be
|
||||
* loadable at run-time.
|
||||
* pubMechFlags
|
||||
* A bit vector indicating all cryptographic mechanisms that should
|
||||
* be turned on by default. This module will become the default
|
||||
* handler for the mechanisms that are set by this bit vector.
|
||||
* pubCipherFlags
|
||||
* A bit vector indicating all SSL or S/MIME cipher functions
|
||||
* supported by the module. Most modules will pas in 0x0 for this
|
||||
* parameter.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server and requests the .so
|
||||
* file on UNIX or .dll file on Windows be loaded as a PKCS11 module and
|
||||
* be stored in the psm security module database. The module will be stored
|
||||
* with the name moduleName that is passed in and will always expect the
|
||||
* library to live at the path passed in via the parameter libraryPath.
|
||||
* The pubMechFlags tell the psm server how this module should be used.
|
||||
* Valid values are the #define constants defined at the beginning of
|
||||
* this file.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the module was successfully loaded
|
||||
* and placed in the security module database of psm. Any other return value
|
||||
* indicates an error and means the module was not loaded successfully and
|
||||
* not stored in the psm server's security module database.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_AddNewModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
char *libraryPath,
|
||||
unsigned long pubMechFlags,
|
||||
unsigned long pubCipherFlags);
|
||||
|
||||
CMT_END_EXTERN_C
|
||||
|
||||
#endif /*_CMTJS_H_*/
|
||||
75
mozilla/security/psm/lib/client/cmtmac.c
Normal file
75
mozilla/security/psm/lib/client/cmtmac.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*- 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 "cmtmac.h"
|
||||
#include "macsocket.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifndef XP_MAC
|
||||
#error Link with the builtin strdup() on your platform.
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
my_strcpy(char *dest, const char *source)
|
||||
{
|
||||
char *i = dest;
|
||||
const char *j = source;
|
||||
while(*j)
|
||||
*i++ = *j++;
|
||||
*i = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
my_strlen(const char *str)
|
||||
{
|
||||
const char *c = str;
|
||||
int i = 0;
|
||||
|
||||
while(*c++ != '\0')
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
char * strdup(const char *oldstr)
|
||||
{
|
||||
/* used to keep the mac client library from referring to strdup elsewhere */
|
||||
char *newstr;
|
||||
|
||||
newstr = (char *) malloc(my_strlen(oldstr)+1);
|
||||
if (newstr)
|
||||
my_strcpy(newstr, oldstr);
|
||||
return newstr;
|
||||
}
|
||||
|
||||
40
mozilla/security/psm/lib/client/cmtmac.h
Normal file
40
mozilla/security/psm/lib/client/cmtmac.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- 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 __CMTMAC_H__
|
||||
#define __CMTMAC_H__
|
||||
|
||||
char * strdup(const char *str);
|
||||
|
||||
#endif
|
||||
119
mozilla/security/psm/lib/client/cmtpasswd.c
Normal file
119
mozilla/security/psm/lib/client/cmtpasswd.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/************************************************************************
|
||||
* Code to handle password requests from the the PSM module.
|
||||
*
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
|
||||
void CMT_SetAppFreeCallback(PCMT_CONTROL control,
|
||||
applicationFreeCallback_fn f)
|
||||
{
|
||||
control->userFuncs.userFree = f;
|
||||
}
|
||||
|
||||
void CMT_ServicePasswordRequest(PCMT_CONTROL cm_control, CMTItem * requestData)
|
||||
{
|
||||
CMTItem response = {0, NULL, 0};
|
||||
PasswordRequest request;
|
||||
PasswordReply reply;
|
||||
void * clientContext;
|
||||
|
||||
/********************************************
|
||||
* What we trying to do here:
|
||||
* 1) Throw up a dialog box and request a password.
|
||||
* 2) Create a message and send it to the PSM module.
|
||||
********************************************
|
||||
*/
|
||||
|
||||
/* Decode the request */
|
||||
if (CMT_DecodeMessage(PasswordRequestTemplate, &request, requestData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(request.clientContext);
|
||||
|
||||
if (cm_control->userFuncs.promptCallback == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
reply.passwd =
|
||||
cm_control->userFuncs.promptCallback(cm_control->userFuncs.promptArg,
|
||||
request.prompt, clientContext, 1);
|
||||
reply.tokenID = request.tokenKey;
|
||||
if (!reply.passwd) {
|
||||
/* the user cancelled the prompt or other errors occurred */
|
||||
reply.result = -1;
|
||||
}
|
||||
else {
|
||||
/* note that this includes an empty string (zero length password) */
|
||||
reply.result = 0;
|
||||
}
|
||||
|
||||
/* Encode the reply */
|
||||
if (CMT_EncodeMessage(PasswordReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message response type */
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_AUTH_EVENT;
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
goto done;
|
||||
loser:
|
||||
/* something has gone wrong */
|
||||
|
||||
done:
|
||||
/*clean up anyway */
|
||||
/* We can't just free up memory allocated by the host
|
||||
application because the versions of free may not match up.
|
||||
When you run the plug-in with an optimized older browser,
|
||||
you'll see tons of Asserts (why they still have asserts in an
|
||||
optimized build is a different question, but without them
|
||||
I wouldn't have figured out this problem) about a pointer not
|
||||
being a valid heap pointer and eventually crash. This was
|
||||
the offending free line.
|
||||
So we need to call a function within the browser that
|
||||
calls the free linked in with it. js_free is
|
||||
such a function. But this is extremely ugly.
|
||||
*/
|
||||
if (reply.passwd)
|
||||
cm_control->userFuncs.userFree(reply.passwd);
|
||||
if (request.prompt)
|
||||
free(request.prompt);
|
||||
return;
|
||||
}
|
||||
|
||||
636
mozilla/security/psm/lib/client/cmtpkcs7.c
Normal file
636
mozilla/security/psm/lib/client/cmtpkcs7.c
Normal file
@@ -0,0 +1,636 @@
|
||||
/* -*- 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, (short)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;
|
||||
/* Let's see if doing a poll first gets rid of a weird bug where we
|
||||
* lock up the client.
|
||||
*/
|
||||
#ifndef XP_MAC
|
||||
if (control->sockFuncs.select(sockArr,2,1) != NULL)
|
||||
#endif
|
||||
{
|
||||
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, (short)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;
|
||||
}
|
||||
479
mozilla/security/psm/lib/client/cmtres.c
Normal file
479
mozilla/security/psm/lib/client/cmtres.c
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
270
mozilla/security/psm/lib/client/cmtrng.c
Normal file
270
mozilla/security/psm/lib/client/cmtrng.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
cmtrng.c -- Support for PSM random number generator and the seeding
|
||||
thereof with data from the client.
|
||||
|
||||
Created by mwelch 1999 Oct 21
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
#include <string.h>
|
||||
|
||||
CMTStatus
|
||||
CMT_EnsureInitializedRNGBuf(PCMT_CONTROL control)
|
||||
{
|
||||
if (control->rng.outBuf == NULL)
|
||||
{
|
||||
control->rng.outBuf = (char *) calloc(RNG_OUT_BUFFER_LEN, sizeof(char));
|
||||
if (control->rng.outBuf == NULL)
|
||||
goto loser;
|
||||
|
||||
control->rng.validOutBytes = 0;
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
control->rng.out_end = control->rng.out_cur + RNG_OUT_BUFFER_LEN;
|
||||
|
||||
control->rng.inBuf = (char *) calloc(RNG_IN_BUFFER_LEN, sizeof(char));
|
||||
if (control->rng.outBuf == NULL)
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control->rng.outBuf != NULL)
|
||||
{
|
||||
free(control->rng.outBuf);
|
||||
control->rng.outBuf = NULL;
|
||||
}
|
||||
if (control->rng.inBuf != NULL)
|
||||
{
|
||||
free(control->rng.inBuf);
|
||||
control->rng.inBuf = NULL;
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CMT_RequestPSMRandomData(PCMT_CONTROL control,
|
||||
void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
SingleNumMessage req;
|
||||
SingleItemMessage reply;
|
||||
CMTItem message;
|
||||
size_t rv = 0;
|
||||
|
||||
/* Parameter checking */
|
||||
if (!control || !buf || (maxbytes == 0))
|
||||
goto loser;
|
||||
|
||||
/* Initialization. */
|
||||
memset(&reply, 0, sizeof(SingleItemMessage));
|
||||
|
||||
/* Ask PSM for the data. */
|
||||
req.value = maxbytes;
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &req) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_MISC_ACTION | SSM_MISC_GET_RNG_DATA;
|
||||
|
||||
/* 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_MISC_ACTION | SSM_MISC_GET_RNG_DATA))
|
||||
goto loser;
|
||||
|
||||
/* Decode message */
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* Success - fill the return buf with what we got */
|
||||
if (reply.item.len > maxbytes)
|
||||
reply.item.len = maxbytes;
|
||||
|
||||
memcpy(buf, reply.item.data, reply.item.len);
|
||||
rv = reply.item.len;
|
||||
|
||||
loser:
|
||||
if (reply.item.data)
|
||||
free(reply.item.data);
|
||||
if (message.data)
|
||||
free(message.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t
|
||||
CMT_GenerateRandomBytes(PCMT_CONTROL control,
|
||||
void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
CMUint32 remaining = maxbytes;
|
||||
CMT_RNGState *rng = &(control->rng);
|
||||
char *walk = (char *) buf;
|
||||
|
||||
/* Is there already enough in the incoming cache? */
|
||||
while(remaining > rng->validInBytes)
|
||||
{
|
||||
/* Get what we have on hand. */
|
||||
memcpy(walk, rng->in_cur, rng->validInBytes);
|
||||
walk += rng->validInBytes;
|
||||
remaining -= rng->validInBytes;
|
||||
|
||||
/* Request a buffer from PSM. */
|
||||
rng->validInBytes = CMT_RequestPSMRandomData(control,
|
||||
rng->inBuf,
|
||||
RNG_IN_BUFFER_LEN);
|
||||
if (rng->validInBytes == 0)
|
||||
return (maxbytes - remaining); /* call failed */
|
||||
rng->in_cur = rng->inBuf;
|
||||
}
|
||||
if (remaining > 0)
|
||||
{
|
||||
memcpy(walk, rng->in_cur, remaining);
|
||||
rng->in_cur += remaining;
|
||||
rng->validInBytes -= remaining;
|
||||
}
|
||||
return maxbytes;
|
||||
}
|
||||
|
||||
void
|
||||
cmt_rng_xor(void *dstBuf, void *srcBuf, int len)
|
||||
{
|
||||
unsigned char *s = (unsigned char*) srcBuf;
|
||||
unsigned char *d = (unsigned char*) dstBuf;
|
||||
unsigned char tmp;
|
||||
int i;
|
||||
|
||||
for(i=0; i<len; i++, s++, d++)
|
||||
{
|
||||
tmp = *d;
|
||||
/* I wish C had circular shift operators. So do others on the team. */
|
||||
tmp = ((tmp << 1) | (tmp >> 7));
|
||||
*d = tmp ^ *s;
|
||||
}
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_RandomUpdate(PCMT_CONTROL control, void *data, size_t numbytes)
|
||||
{
|
||||
size_t dataLeft = numbytes, cacheLeft;
|
||||
char *walk = (char *) data;
|
||||
|
||||
if (CMT_EnsureInitializedRNGBuf(control) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* If we have more than what the buffer can handle, wrap around. */
|
||||
cacheLeft = (control->rng.out_end - control->rng.out_cur);
|
||||
while (dataLeft >= cacheLeft)
|
||||
{
|
||||
cmt_rng_xor(control->rng.out_cur, walk, cacheLeft);
|
||||
walk += cacheLeft;
|
||||
dataLeft -= cacheLeft;
|
||||
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
|
||||
/* Max out used space */
|
||||
control->rng.validOutBytes = cacheLeft = RNG_OUT_BUFFER_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
We now have less seed data available than we do space in the buf.
|
||||
Write what we have and update validOutBytes if we're not looping already.
|
||||
*/
|
||||
cmt_rng_xor(control->rng.out_cur, walk, dataLeft);
|
||||
control->rng.out_cur += dataLeft;
|
||||
if (control->rng.validOutBytes < RNG_OUT_BUFFER_LEN)
|
||||
control->rng.validOutBytes += dataLeft;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
size_t
|
||||
CMT_GetNoise(PCMT_CONTROL control, void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
/* ### mwelch - GetNoise and GenerateRandomBytes can be the
|
||||
same function now, because presumably the RNG is being
|
||||
seeded with environmental noise on the PSM end before we
|
||||
make any of these requests */
|
||||
return CMT_GenerateRandomBytes(control, buf, maxbytes);
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_FlushPendingRandomData(PCMT_CONTROL control)
|
||||
{
|
||||
CMTItem message;
|
||||
|
||||
memset(&message, 0, sizeof(CMTItem));
|
||||
|
||||
if (CMT_EnsureInitializedRNGBuf(control) != CMTSuccess)
|
||||
return CMTFailure; /* couldn't initialize RNG buffer */
|
||||
|
||||
if (control->rng.validOutBytes == 0)
|
||||
return CMTSuccess; /* no random data available == we're flushed */
|
||||
|
||||
/* We have random data available. Send this to PSM.
|
||||
We're sending an event, so no reply is needed. */
|
||||
message.type = SSM_EVENT_MESSAGE
|
||||
| SSM_MISC_ACTION
|
||||
| SSM_MISC_PUT_RNG_DATA;
|
||||
message.len = control->rng.validOutBytes;
|
||||
message.data = (unsigned char *) calloc(message.len, sizeof(char));
|
||||
if (!message.data)
|
||||
goto loser;
|
||||
memcpy(message.data, control->rng.outBuf, message.len);
|
||||
|
||||
if (CMT_TransmitMessage(control, &message) == CMTFailure)
|
||||
goto loser;
|
||||
|
||||
/* Clear the RNG ring buffer, we've used that data */
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
control->rng.validOutBytes = 0;
|
||||
/* zero the buffer, because we XOR in new data */
|
||||
memset(control->rng.outBuf, 0, RNG_OUT_BUFFER_LEN);
|
||||
|
||||
goto done;
|
||||
loser:
|
||||
if (message.data)
|
||||
free(message.data);
|
||||
return CMTFailure;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
237
mozilla/security/psm/lib/client/cmtsdr.c
Normal file
237
mozilla/security/psm/lib/client/cmtsdr.c
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
cmtsdr.c -- Support for the Secret Decoder Ring, which provides
|
||||
encryption and decryption using stored keys.
|
||||
|
||||
Created by thayes 18 April 2000
|
||||
*/
|
||||
#include "stddef.h"
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "protocolshr.h"
|
||||
#include "rsrcids.h"
|
||||
#include <string.h>
|
||||
|
||||
#undef PROCESS_LOCALLY
|
||||
|
||||
/* Encryption result - contains the key id and the resulting data */
|
||||
/* An empty key id indicates that NO encryption was performed */
|
||||
typedef struct EncryptionResult
|
||||
{
|
||||
CMTItem keyid;
|
||||
CMTItem data;
|
||||
} EncryptionResult;
|
||||
|
||||
/* Constants for testing */
|
||||
static const char *kPrefix = "Encrypted:";
|
||||
|
||||
static CMTItem
|
||||
CMT_CopyDataToItem(const unsigned char *data, CMUint32 len)
|
||||
{
|
||||
CMTItem item;
|
||||
|
||||
item.data = (unsigned char*) calloc(len, 1);
|
||||
item.len = len;
|
||||
memcpy(item.data, data, len);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
static CMTStatus
|
||||
tmp_SendMessage(PCMT_CONTROL control, CMTItem *message)
|
||||
{
|
||||
#ifndef PROCESS_LOCALLY
|
||||
return CMT_SendMessage(control, message);
|
||||
#else
|
||||
if (message->type == SSM_SDR_ENCRYPT_REQUEST)
|
||||
return CMT_DoEncryptionRequest(message);
|
||||
else if (message->type == SSM_SDR_DECRYPT_REQUEST)
|
||||
return CMT_DoDecryptionRequest(message);
|
||||
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
/* End test code */
|
||||
|
||||
CMTStatus
|
||||
CMT_SDREncrypt(PCMT_CONTROL control, void *ctx,
|
||||
const unsigned char *key, CMUint32 keyLen,
|
||||
const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem message;
|
||||
EncryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.keyid = CMT_CopyDataToItem(key, keyLen);
|
||||
request.data = CMT_CopyDataToItem(data, dataLen);
|
||||
request.ctx = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(EncryptRequestTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_SDR_ENCRYPT_REQUEST;
|
||||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_ENCRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
*resultLen = reply.item.len;
|
||||
|
||||
reply.item.data = 0;
|
||||
|
||||
loser:
|
||||
if (message.data) free(message.data);
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SDRDecrypt(PCMT_CONTROL control, void *ctx,
|
||||
const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMTItem message;
|
||||
DecryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.data = CMT_CopyDataToItem(data, dataLen);
|
||||
request.ctx = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(DecryptRequestTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_SDR_DECRYPT_REQUEST;
|
||||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_DECRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
*resultLen = reply.item.len;
|
||||
|
||||
reply.item.data = 0;
|
||||
|
||||
loser:
|
||||
if (message.data) free(message.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SDRChangePassword(PCMT_CONTROL control, void *ctx)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem message;
|
||||
SingleItemMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.item = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = (SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_UI|SSM_UI_CHANGE_PASSWORD);
|
||||
|
||||
/* Send */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type !=
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_UI|SSM_UI_CHANGE_PASSWORD)) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
loser:
|
||||
if (request.item.data) free(request.item.data);
|
||||
if (message.data) free(message.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
467
mozilla/security/psm/lib/client/cmtssl.c
Normal file
467
mozilla/security/psm/lib/client/cmtssl.c
Normal file
@@ -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;
|
||||
}
|
||||
636
mozilla/security/psm/lib/client/cmtutils.c
Normal file
636
mozilla/security/psm/lib/client/cmtutils.c
Normal file
@@ -0,0 +1,636 @@
|
||||
/* -*- 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);
|
||||
|
||||
/* Send the message header */
|
||||
sent = CMT_WriteThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (sent != sizeof(CMTMessageHeader)) {
|
||||
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 numread, rv;
|
||||
|
||||
/* Get the message header */
|
||||
numread = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (numread != sizeof(CMTMessageHeader)) {
|
||||
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;
|
||||
}
|
||||
|
||||
numread = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)(response->data), response->len);
|
||||
if (numread != response->len) {
|
||||
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) {
|
||||
CMInt32 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);
|
||||
}
|
||||
75
mozilla/security/psm/lib/client/cmtutils.h
Normal file
75
mozilla/security/psm/lib/client/cmtutils.h
Normal file
@@ -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 * sock);
|
||||
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__ */
|
||||
|
||||
44
mozilla/security/psm/lib/client/config.mk
Normal file
44
mozilla/security/psm/lib/client/config.mk
Normal file
@@ -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 =
|
||||
|
||||
125
mozilla/security/psm/lib/client/makefile.win
Normal file
125
mozilla/security/psm/lib/client/makefile.win
Normal file
@@ -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=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 \
|
||||
.\$(OBJDIR)\cmtsdr.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
|
||||
|
||||
64
mozilla/security/psm/lib/client/manifest.mn
Normal file
64
mozilla/security/psm/lib/client/manifest.mn
Normal file
@@ -0,0 +1,64 @@
|
||||
#
|
||||
# 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 \
|
||||
cmtsdr.c \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = nspr security
|
||||
|
||||
LIBRARY_NAME = cmt
|
||||
|
||||
INCLUDES += -I$(CORE_DEPTH)/include
|
||||
128
mozilla/security/psm/lib/client/sample/Makefile
Normal file
128
mozilla/security/psm/lib/client/sample/Makefile
Normal file
@@ -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
|
||||
|
||||
250
mozilla/security/psm/lib/client/sample/appsock.c
Normal file
250
mozilla/security/psm/lib/client/sample/appsock.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/* -*- 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 "appsock.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <netinet/tcp.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
CMT_SocketFuncs socketFuncs = {
|
||||
APP_GetSocket,
|
||||
APP_Connect,
|
||||
APP_VerifyUnixSocket,
|
||||
APP_Send,
|
||||
APP_Select,
|
||||
APP_Receive,
|
||||
APP_Shutdown,
|
||||
APP_Close
|
||||
};
|
||||
|
||||
CMTSocket APP_GetSocket(int unixSock)
|
||||
{
|
||||
APPSocket *sock;
|
||||
int on = 1;
|
||||
|
||||
#ifndef XP_UNIX
|
||||
if (unixSock) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
sock = malloc(sizeof(APPSocket));
|
||||
if (sock == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (unixSock) {
|
||||
sock->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
} else {
|
||||
sock->sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
if (sock->sock < 0) {
|
||||
free(sock);
|
||||
return NULL;
|
||||
}
|
||||
if (!unixSock &&
|
||||
setsockopt(sock->sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&on,
|
||||
sizeof(on))) {
|
||||
free(sock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->isUnix = unixSock;
|
||||
#ifdef XP_UNIX
|
||||
memset (&sock->servAddr, 0, sizeof(struct sockaddr_un));
|
||||
#endif
|
||||
return (CMTSocket)sock;
|
||||
}
|
||||
|
||||
CMTStatus APP_Connect(CMTSocket sock, short port, char *path)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
struct sockaddr_in iServAddr;
|
||||
const struct sockaddr *servAddr;
|
||||
size_t addrLen;
|
||||
int error;
|
||||
|
||||
if (cmSock->isUnix){
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
cmSock->servAddr.sun_family = AF_UNIX;
|
||||
memcpy(&cmSock->servAddr.sun_path, path, strlen(path)+1);
|
||||
servAddr = (const struct sockaddr*)&cmSock->servAddr;
|
||||
addrLen = sizeof(cmSock->servAddr);
|
||||
#endif
|
||||
} else {
|
||||
iServAddr.sin_family = AF_INET;
|
||||
iServAddr.sin_port = htons(port);
|
||||
iServAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
servAddr = (const struct sockaddr*)&iServAddr;
|
||||
addrLen = sizeof(struct sockaddr_in);
|
||||
}
|
||||
while (connect(cmSock->sock, servAddr, addrLen) != 0) {
|
||||
#ifdef WIN32
|
||||
error = WSAGetLastError();
|
||||
if (error == WSAEISCONN) {
|
||||
break;
|
||||
}
|
||||
if ((error != WSAEINPROGRESS) && (error != WSAEWOULDBLOCK) &&
|
||||
(error!= WSAEINVAL)) {
|
||||
goto loser;
|
||||
}
|
||||
#else
|
||||
error = errno;
|
||||
if (error == EISCONN) {
|
||||
break;
|
||||
}
|
||||
if (error != EINPROGRESS) {
|
||||
goto loser;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus APP_VerifyUnixSocket(CMTSocket sock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
struct stat statbuf;
|
||||
|
||||
if (!cmSock->isUnix) {
|
||||
return CMTFailure;
|
||||
}
|
||||
rv = stat(cmSock->servAddr.sun_path, &statbuf);
|
||||
if (rv < 0) {
|
||||
goto loser;
|
||||
}
|
||||
if (statbuf.st_uid != geteuid()) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
close(cmSock->sock);
|
||||
free(cmSock);
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t APP_Send(CMTSocket sock, void *buffer, size_t length)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*) sock;
|
||||
|
||||
return send(cmSock->sock, buffer, length, 0);
|
||||
}
|
||||
|
||||
CMTSocket APP_Select(CMTSocket *socks, int numsocks, int poll)
|
||||
{
|
||||
APPSocket **sockArr = (APPSocket**)socks;
|
||||
SOCKET nsocks = 0;
|
||||
int i, rv;
|
||||
struct timeval timeout;
|
||||
fd_set readfds;
|
||||
|
||||
#ifdef WIN32
|
||||
win_startover:
|
||||
#endif
|
||||
FD_ZERO(&readfds);
|
||||
for (i=0; i<numsocks; i++) {
|
||||
FD_SET(sockArr[i]->sock, &readfds);
|
||||
if (sockArr[i]->sock > nsocks) {
|
||||
nsocks = sockArr[i]->sock;
|
||||
}
|
||||
}
|
||||
if (poll) {
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
}
|
||||
rv = select(nsocks+1, &readfds, NULL, NULL, (poll) ? &timeout : NULL);
|
||||
|
||||
#ifdef WIN32
|
||||
/* XXX Win95/98 Bug (Q177346)
|
||||
* select() with no timeout might return even if there is no data
|
||||
* pending or no error has occurred. To get around this problem,
|
||||
* we loop if these erroneous conditions happen.
|
||||
*/
|
||||
if (poll == 0 && rv == 0) {
|
||||
goto win_startover;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Figure out which socket was selected */
|
||||
if (rv == -1 || rv == 0) {
|
||||
goto loser;
|
||||
}
|
||||
for (i=0; i<numsocks; i++) {
|
||||
if (FD_ISSET(sockArr[i]->sock, &readfds)) {
|
||||
return (CMTSocket)sockArr[i];
|
||||
}
|
||||
}
|
||||
loser:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t APP_Receive(CMTSocket sock, void *buffer, size_t bufSize)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
|
||||
return recv(cmSock->sock, buffer, bufSize, 0);
|
||||
}
|
||||
|
||||
CMTStatus APP_Shutdown(CMTSocket sock)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
|
||||
rv = shutdown(cmSock->sock, 1);
|
||||
return (rv == 0) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus APP_Close(CMTSocket sock)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
rv = close(cmSock->sock);
|
||||
#else
|
||||
rv = closesocket(cmSock->sock);
|
||||
#endif
|
||||
free(cmSock);
|
||||
return (rv == 0) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
69
mozilla/security/psm/lib/client/sample/appsock.h
Normal file
69
mozilla/security/psm/lib/client/sample/appsock.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- 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 _APPSOCK_H_
|
||||
#define _APPSOCK_H_
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#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>
|
||||
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
typedef struct APPSocketStr {
|
||||
SOCKET sock;
|
||||
int isUnix;
|
||||
#ifdef XP_UNIX
|
||||
struct sockaddr_un servAddr;
|
||||
#endif
|
||||
} APPSocket;
|
||||
|
||||
extern CMT_SocketFuncs socketFuncs;
|
||||
|
||||
CMTStatus APP_Close(CMTSocket sock);
|
||||
CMTStatus APP_Shutdown(CMTSocket sock);
|
||||
size_t APP_Receive(CMTSocket sock, void *buffer, size_t bufSize);
|
||||
CMTSocket APP_Select(CMTSocket *socks, int numsocks, int poll);
|
||||
size_t APP_Send(CMTSocket sock, void *buffer, size_t length);
|
||||
CMTStatus APP_VerifyUnixSocket(CMTSocket sock);
|
||||
CMTStatus APP_Connect(CMTSocket sock, short port, char *path);
|
||||
CMTSocket APP_GetSocket(int unixSock);
|
||||
|
||||
|
||||
#endif /* _APPSOCK_H_ */
|
||||
44
mozilla/security/psm/lib/client/sample/config.mk
Normal file
44
mozilla/security/psm/lib/client/sample/config.mk
Normal file
@@ -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 =
|
||||
|
||||
52
mozilla/security/psm/lib/client/sample/manifest.mn
Normal file
52
mozilla/security/psm/lib/client/sample/manifest.mn
Normal file
@@ -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
|
||||
|
||||
346
mozilla/security/psm/lib/client/sample/sample.c
Normal file
346
mozilla/security/psm/lib/client/sample/sample.c
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
99
mozilla/security/psm/lib/client/test.c
Normal file
99
mozilla/security/psm/lib/client/test.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 "cmt.h"
|
||||
|
||||
CMTStatus myCallback(CMTControl * control, CMTItem * event, void * arg);
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CMTItem * msg, * event = NULL;
|
||||
CMTStatus status;
|
||||
int socket, datasocket;
|
||||
int sent;
|
||||
CMTControl * connect;
|
||||
char * buffer = "some weird text that I feel like passing to server";
|
||||
|
||||
connect = CMT_ControlConnect(myCallback, event);
|
||||
|
||||
msg = CMT_ConstructMessage(10);
|
||||
|
||||
msg->type = (int)CMTClientMessage;
|
||||
sprintf((char *)msg->data, "first msg!");
|
||||
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
CMT_FreeEvent(event);
|
||||
event = NULL;
|
||||
|
||||
sprintf((char *)msg->data, "second msg");
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
datasocket = CMT_DataConnect(connect, NULL);
|
||||
if (datasocket < 0)
|
||||
perror("CMT_DataConnect");
|
||||
|
||||
sent = write(datasocket, (void *)buffer, strlen(buffer));
|
||||
sent = write(datasocket, (void *)buffer, strlen(buffer));
|
||||
|
||||
close(datasocket);
|
||||
|
||||
msg->type = (int)CMTClientMessage;
|
||||
sprintf((char *)msg->data, "third msg!");
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
status = CMT_CloseControlConnection(connect);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_CloseControl");
|
||||
|
||||
CMT_FreeMessage(msg);
|
||||
CMT_FreeEvent(event);
|
||||
}
|
||||
|
||||
CMTStatus myCallback(CMTControl * control, CMTItem * event, void * arg)
|
||||
{
|
||||
if (event)
|
||||
printf("Event received is : type %d, data %s\n", event->type, event->data);
|
||||
else printf("No event!\n");
|
||||
if (arg)
|
||||
printf("Arg is %s\n", (char *)arg);
|
||||
else printf("No arg!\n");
|
||||
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
BIN
mozilla/security/psm/lib/macbuild/PSMClient.mcp
Normal file
BIN
mozilla/security/psm/lib/macbuild/PSMClient.mcp
Normal file
Binary file not shown.
3
mozilla/security/psm/lib/macbuild/PSMPrefix.h
Normal file
3
mozilla/security/psm/lib/macbuild/PSMPrefix.h
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
#include "MacPrefix.h"
|
||||
2
mozilla/security/psm/lib/macbuild/PSMPrefix_debug.h
Normal file
2
mozilla/security/psm/lib/macbuild/PSMPrefix_debug.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
#include "MacPrefix_debug.h"
|
||||
BIN
mozilla/security/psm/lib/macbuild/PSMProtocol.mcp
Normal file
BIN
mozilla/security/psm/lib/macbuild/PSMProtocol.mcp
Normal file
Binary file not shown.
27
mozilla/security/psm/lib/makefile.win
Normal file
27
mozilla/security/psm/lib/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
DIRS = client protocol
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
43
mozilla/security/psm/lib/manifest.mn
Normal file
43
mozilla/security/psm/lib/manifest.mn
Normal file
@@ -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
|
||||
3
mozilla/security/psm/lib/protocol/MANIFEST
Normal file
3
mozilla/security/psm/lib/protocol/MANIFEST
Normal file
@@ -0,0 +1,3 @@
|
||||
obscure.h
|
||||
rsrcids.h
|
||||
ssmdefs.h
|
||||
74
mozilla/security/psm/lib/protocol/Makefile
Executable file
74
mozilla/security/psm/lib/protocol/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! 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). #
|
||||
#######################################################################
|
||||
include config.mk
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
64
mozilla/security/psm/lib/protocol/Makefile.in
Normal file
64
mozilla/security/psm/lib/protocol/Makefile.in
Normal file
@@ -0,0 +1,64 @@
|
||||
#! 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 \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
CSRCS = newproto.c \
|
||||
templates.c \
|
||||
protocolshr.c \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
44
mozilla/security/psm/lib/protocol/config.mk
Normal file
44
mozilla/security/psm/lib/protocol/config.mk
Normal file
@@ -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 =
|
||||
|
||||
124
mozilla/security/psm/lib/protocol/makefile.win
Normal file
124
mozilla/security/psm/lib/protocol/makefile.win
Normal file
@@ -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=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)\protocolshr.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 \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
export:: INSTALL_FILES
|
||||
|
||||
65
mozilla/security/psm/lib/protocol/manifest.mn
Normal file
65
mozilla/security/psm/lib/protocol/manifest.mn
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# 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 = ../../..
|
||||
|
||||
EXPORTS = \
|
||||
protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
CSRCS = newproto.c \
|
||||
protocolshr.c \
|
||||
templates.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
|
||||
|
||||
LIBRARY_NAME = protocol
|
||||
620
mozilla/security/psm/lib/protocol/messages.h
Normal file
620
mozilla/security/psm/lib/protocol/messages.h
Normal file
@@ -0,0 +1,620 @@
|
||||
/* -*- 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;
|
||||
CMBool isModal;
|
||||
char *url;
|
||||
CMTItem clientContext;
|
||||
} UIEvent;
|
||||
|
||||
extern CMTMessageTemplate UIEventTemplate[];
|
||||
extern CMTMessageTemplate OldUIEventTemplate[];
|
||||
|
||||
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[];
|
||||
|
||||
typedef struct EncryptRequestMessage
|
||||
{
|
||||
CMTItem keyid; /* May have length 0 for default */
|
||||
CMTItem data;
|
||||
CMTItem ctx; /* serialized void* ptr */
|
||||
} EncryptRequestMessage;
|
||||
|
||||
extern CMTMessageTemplate EncryptRequestTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage EncryptReplyMessage;
|
||||
#define EncryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
typedef struct DecryptRequestMessage
|
||||
{
|
||||
CMTItem data;
|
||||
CMTItem ctx; /* serialized void* ptr */
|
||||
} DecryptRequestMessage;
|
||||
extern CMTMessageTemplate DecryptRequestTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage DecryptReplyMessage;
|
||||
#define DecryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
#endif /* __MESSAGES_H__ */
|
||||
602
mozilla/security/psm/lib/protocol/newproto.c
Normal file
602
mozilla/security/psm/lib/protocol/newproto.c
Normal file
@@ -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;
|
||||
}
|
||||
102
mozilla/security/psm/lib/protocol/newproto.h
Normal file
102
mozilla/security/psm/lib/protocol/newproto.h
Normal file
@@ -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__ */
|
||||
187
mozilla/security/psm/lib/protocol/obsample.c
Normal file
187
mozilla/security/psm/lib/protocol/obsample.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/* SAMPLE CODE
|
||||
** Illustrates use of SSMObscure object methods.
|
||||
**
|
||||
** Author: Nelson Bolyard June 1999
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "obscure.h"
|
||||
|
||||
|
||||
/* On error, returns -1.
|
||||
** On success, returns non-negative number of unobscured bytes in buf
|
||||
int
|
||||
RecvInitObscureData(int fd, SSMObscureObject * obj, void * buf, int bufSize )
|
||||
{
|
||||
SSMObscureBool done = 0;
|
||||
|
||||
do {
|
||||
int cc;
|
||||
int rv;
|
||||
cc = read(fd, 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(int fd, 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 = malloc(bufLen);
|
||||
if (!initBuf)
|
||||
break;
|
||||
|
||||
len = SSMObscure_SendInit(obj, initBuf);
|
||||
if (len != bufLen)
|
||||
break;
|
||||
|
||||
cc = write(fd, 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;
|
||||
}
|
||||
|
||||
/* This is like write, but it obscures the data first. */
|
||||
/* This code assumes a blocking socket, and so it doesn't handle short
|
||||
** writes.
|
||||
*/
|
||||
int
|
||||
obscuredWrite(SSMObscureObject * obj, int fd, void * buf, int len)
|
||||
{
|
||||
int rv;
|
||||
int cc;
|
||||
|
||||
cc = SSMObscure_Send(obj, buf, len);
|
||||
if (cc <= 0)
|
||||
return cc;
|
||||
rv = write(fd, buf, cc);
|
||||
ASSERT(rv == cc || rv < 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* This is like read, but it unobscures the data after reading it. */
|
||||
int
|
||||
obscuredRead(SSMObscureObject * obj, int fd, void * buf, int len)
|
||||
{
|
||||
int rv;
|
||||
int cc;
|
||||
|
||||
do {
|
||||
cc = read(fd, buf, len);
|
||||
if (cc <= 0)
|
||||
return cc;
|
||||
rv = SSMObscure_Recv(obj, buf, len);
|
||||
} while (rv == 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
SSMObscureObject * sobj;
|
||||
unsigned char buf[8192];
|
||||
|
||||
/* Call this with fd for socket that has just been accepted.
|
||||
** returns -1 on error,
|
||||
** On success, returns non-negative number of bytes received in buf.
|
||||
*/
|
||||
int
|
||||
InitClientObscureObject(int fd)
|
||||
{
|
||||
int rv;
|
||||
|
||||
sobj = SSMObscure_Create(0);
|
||||
if (!sobj)
|
||||
return -1;
|
||||
|
||||
rv = SendInitObscureData(fd, sobj);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
rv = RecvInitObscureData(fd, sobj, buf, sizeof buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Call this with fd for socket that has just been connected.
|
||||
** returns -1 on error,
|
||||
** On success, returns non-negative number of bytes received in buf.
|
||||
*/
|
||||
int
|
||||
InitServerObscureObject(int fd)
|
||||
{
|
||||
int cc;
|
||||
|
||||
sobj = SSMObscure_Create(1);
|
||||
if (!sobj)
|
||||
return -1;
|
||||
|
||||
cc = RecvInitObscureData(fd, sobj, buf, sizeof buf);
|
||||
if (cc < 0)
|
||||
return cc;
|
||||
|
||||
|
||||
rv = SendInitObscureData(fd, sobj);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
136
mozilla/security/psm/lib/protocol/obscure.c
Normal file
136
mozilla/security/psm/lib/protocol/obscure.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include "obspriv.h"
|
||||
#include "newproto.h"
|
||||
|
||||
|
||||
/*
|
||||
** Create a new Obscuring object
|
||||
*/
|
||||
SSMObscureObject *
|
||||
SSMObscure_Create(SSMObscureBool IsServer)
|
||||
{
|
||||
SSMObscureObject * obj;
|
||||
void * priv;
|
||||
|
||||
obj = (SSMObscureObject *) cmt_alloc(sizeof *obj);
|
||||
if (!obj)
|
||||
return obj;
|
||||
/* This needs to be a little more elegant */
|
||||
priv = SSMObscure_InitPrivate(obj, IsServer);
|
||||
if (!priv) {
|
||||
cmt_free(obj);
|
||||
return NULL;
|
||||
}
|
||||
obj->privData = priv;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/* Prepare initial buffer with initial message to send to other side to
|
||||
** establish cryptographic * synchronization.
|
||||
**
|
||||
** If buf is NULL, function returns the size of the buffer that
|
||||
** the caller needs to allocate for sending the initial message.
|
||||
**
|
||||
** If buf is non-null, function returns the number of bytes of data filled
|
||||
** into buf, the amount that the caller should then send to the other side.
|
||||
**
|
||||
*/
|
||||
int
|
||||
SSMObscure_SendInit( SSMObscureObject * obj, void * buf)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->sendInit(obj->privData, buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Obscure "len" bytes in "buf" before sending it.
|
||||
*/
|
||||
int
|
||||
SSMObscure_Send( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->send(obj->privData, buf, len);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** UnObscure "len" bytes in "buf" after receiving it.
|
||||
** This function may absorb some or all of the received bytes, leaving
|
||||
** fewer bytes (possibly none) in the buffer for the application to use
|
||||
** than were in the buffer when the function was called.
|
||||
** Function returns the number of bytes of unobscured data remaining in
|
||||
** buf. Zero means all data was used internally and no data remains
|
||||
** for application use. Negative number means error occurred.
|
||||
*/
|
||||
int
|
||||
SSMObscure_Recv( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->recv(obj->privData, buf, len);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* like _Recv, but returns a flag telling when all initialization info has
|
||||
** been received.
|
||||
*/
|
||||
int
|
||||
SSMObscure_RecvInit( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len,
|
||||
SSMObscureBool * done)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->recvInit(obj->privData, buf, len, done);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destroy the Obscure Object
|
||||
*/
|
||||
int
|
||||
SSMObscure_Destroy(SSMObscureObject * obj)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->destroy(obj->privData);
|
||||
cmt_free(obj);
|
||||
return rv;
|
||||
}
|
||||
|
||||
98
mozilla/security/psm/lib/protocol/obscure.h
Normal file
98
mozilla/security/psm/lib/protocol/obscure.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 __obscure_h__
|
||||
#define __obscure_h__ 1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef unsigned char SSMObscureBool;
|
||||
|
||||
typedef struct SSMObscureObjectStr SSMObscureObject;
|
||||
|
||||
/*
|
||||
** Create a new Obscuring object
|
||||
*/
|
||||
extern SSMObscureObject * SSMObscure_Create(SSMObscureBool IsServer);
|
||||
|
||||
|
||||
/* Prepare initial buffer with initial message to send to other side to
|
||||
** establish cryptographic * synchronization.
|
||||
**
|
||||
** If buf is NULL, function returns the size of the buffer that
|
||||
** the caller needs to allocate for sending the initial message.
|
||||
**
|
||||
** If buf is non-null, function returns the number of bytes of data filled
|
||||
** into buf, the amount that the caller should then send to the other side.
|
||||
**
|
||||
*/
|
||||
extern int SSMObscure_SendInit( SSMObscureObject * obj,
|
||||
void * buf);
|
||||
|
||||
/*
|
||||
** Obscure "len" bytes in "buf" before sending it.
|
||||
*/
|
||||
extern int SSMObscure_Send( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len);
|
||||
|
||||
/*
|
||||
** UnObscure "len" bytes in "buf" after receiving it.
|
||||
** This function may absorb some or all of the received bytes, leaving
|
||||
** fewer bytes (possibly none) in the buffer for the application to use
|
||||
** than were in the buffer when the function was called.
|
||||
** Function returns the number of bytes of unobscured data remaining in
|
||||
** buf. Zero means all data was used internally and no data remains
|
||||
** for application use. Negative number means error occurred.
|
||||
*/
|
||||
extern int SSMObscure_Recv( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len);
|
||||
|
||||
/* like _Recv, but returns a flag telling when all initialization info has
|
||||
** been received.
|
||||
*/
|
||||
extern int SSMObscure_RecvInit( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len,
|
||||
SSMObscureBool * done);
|
||||
|
||||
/*
|
||||
** Destroy the Obscure Object
|
||||
*/
|
||||
extern int SSMObscure_Destroy(SSMObscureObject * obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __obscure_h__ */
|
||||
115
mozilla/security/psm/lib/protocol/obspriv.c
Normal file
115
mozilla/security/psm/lib/protocol/obspriv.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 <string.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;
|
||||
|
||||
obj->privData = (void *)priv;
|
||||
obj->destroy = ssmObscure_Destroy;
|
||||
obj->send = ssmObscure_Send;
|
||||
obj->recv = ssmObscure_Recv;
|
||||
obj->sendInit = ssmObscure_SendInit;
|
||||
obj->recvInit = ssmObscure_RecvInit;
|
||||
|
||||
return priv;
|
||||
}
|
||||
|
||||
obsInitFn SSMObscure_InitPrivate = ssmObscure_InitPrivate;
|
||||
63
mozilla/security/psm/lib/protocol/obspriv.h
Normal file
63
mozilla/security/psm/lib/protocol/obspriv.h
Normal file
@@ -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.
|
||||
*/
|
||||
#include "obscure.h"
|
||||
|
||||
typedef void * (* obsInitFn) (SSMObscureObject * instance,
|
||||
SSMObscureBool IsServer);
|
||||
typedef int (* obsDestroyFn) (void * priv);
|
||||
typedef int (* obsSendFn) (void * priv, void * buf, unsigned int len);
|
||||
typedef int (* obsRecvFn) (void * priv, void * buf, unsigned int len);
|
||||
typedef int (* obsSendInitFn)(void * priv, void * buf);
|
||||
typedef int (* obsRecvInitFn)(void * priv, void * buf, unsigned int len,
|
||||
SSMObscureBool * done);
|
||||
|
||||
struct SSMObscureObjectStr {
|
||||
void * privData;
|
||||
obsDestroyFn destroy;
|
||||
obsSendFn send;
|
||||
obsRecvFn recv;
|
||||
obsSendInitFn sendInit;
|
||||
obsRecvInitFn recvInit;
|
||||
};
|
||||
|
||||
|
||||
/* This is common to the beginning of all versions of the obscuring protocol */
|
||||
struct SSMInitMsgHdrStr {
|
||||
short version;
|
||||
short length;
|
||||
};
|
||||
|
||||
typedef struct SSMInitMsgHdrStr SSMInitMsgHdr;
|
||||
|
||||
extern obsInitFn SSMObscure_InitPrivate;
|
||||
|
||||
141
mozilla/security/psm/lib/protocol/protocol.h
Normal file
141
mozilla/security/psm/lib/protocol/protocol.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
protocol.h - Definitions of various items to support the PSM protocol.
|
||||
*/
|
||||
|
||||
#ifndef __PROTOCOL_H__
|
||||
#define __PROTOCOL_H__
|
||||
|
||||
|
||||
#include "rsrcids.h"
|
||||
|
||||
#define SSMPRStatus SSMStatus
|
||||
#define SSMPR_SUCCESS SSM_SUCCESS
|
||||
#define SSMPR_FAILURE SSM_FAILURE
|
||||
|
||||
#define SSMPR_INVALID_ARGUMENT_ERROR PR_INVALID_ARGUMENT_ERROR
|
||||
#define SSMPR_OUT_OF_MEMORY_ERROR PR_OUT_OF_MEMORY_ERROR
|
||||
|
||||
#define SSMPRInt32 PRInt32
|
||||
#define SSMPRUint32 PRUint32
|
||||
|
||||
#define SSMPR_ntohl PR_ntohl
|
||||
#define SSMPR_htonl PR_htonl
|
||||
#define SSMPORT_Free PORT_Free
|
||||
#define SSMPORT_ZAlloc PORT_ZAlloc
|
||||
|
||||
#define SSMPR_SetError PR_SetError
|
||||
#define SSMPR_GetError PR_GetError
|
||||
#define SSMPORT_SetError PORT_SetError
|
||||
#define SSMPORT_GetError PORT_GetError
|
||||
|
||||
/*
|
||||
Current version of PSM protocol.
|
||||
Increment this value when the protocol changes.
|
||||
*/
|
||||
|
||||
#define SSMSTRING_PADDED_LENGTH(x) ((((x)+3)/4)*4)
|
||||
#define SSMPORT_ZNEW(type) (type*)SSMPORT_ZAlloc(sizeof(type))
|
||||
#define SSMPORT_ZNewArray(type,size) (type*)SSMPORT_ZAlloc(sizeof(type)*(size))
|
||||
/* Various message structs */
|
||||
|
||||
struct _SSMHelloRequest {
|
||||
CMUint32 m_version; /* Protocol version supported by client */
|
||||
struct _SSMString m_profileName; /* Name of user profile (where to find
|
||||
certs etc) */
|
||||
};
|
||||
|
||||
struct _SSMHelloReply {
|
||||
CMInt32 m_result; /* Error, if any, which occurred
|
||||
(0 == success) */
|
||||
CMUint32 m_version; /* Protocol version supported by PSM */
|
||||
struct _SSMString m_nonce; /* Session nonce -- must be written to data channels */
|
||||
};
|
||||
|
||||
struct _SSMRequestSSLDataConnection
|
||||
{
|
||||
CMUint32 m_flags; /* Flags to indicate to SSM what to do with
|
||||
the connection */
|
||||
CMUint32 m_port; /* Port number to connect to */
|
||||
struct _SSMString m_hostIP; /* IP address of final target machine (not proxy) */
|
||||
/* struct _SSMString m_hostName; Host name of target machine (for server auth) -- not accessed directly */
|
||||
};
|
||||
|
||||
struct _SSMReplySSLDataConnection {
|
||||
CMInt32 m_result; /* Error, if any, which occurred (0 == success) */
|
||||
CMUint32 m_connectionID; /* Connection ID of newly opened channel */
|
||||
CMUint32 m_port; /* Port number to which to connect on PSM */
|
||||
};
|
||||
|
||||
|
||||
struct _SSMRequestSecurityStatus {
|
||||
CMUint32 m_connectionID; /* ID of connection of which to stat */
|
||||
};
|
||||
|
||||
struct _SSMReplySecurityStatus {
|
||||
CMInt32 m_result; /* Error, if any, which occurred (0 == success) */
|
||||
CMUint32 m_keySize; /* Key size */
|
||||
CMUint32 m_secretKeySize; /* Secret key size */
|
||||
struct _SSMString m_cipherName; /* Name of cipher in use */
|
||||
/* SSMString m_certificate; -- DER encoded cert
|
||||
We do not access this as a field, we have to skip over m_cipherName */
|
||||
};
|
||||
|
||||
/*
|
||||
Use this macro to jump over strings.
|
||||
For example, if you wanted to access m_certificate above,
|
||||
use a line like the following:
|
||||
|
||||
char *ptr = &(reply->m_cipherName) + SSM_SIZEOF_STRING(reply->m_cipherName);
|
||||
*/
|
||||
#define SSM_SIZEOF_STRING(str) (SSMSTRING_PADDED_LENGTH(PR_ntohl((str).m_length)) + sizeof(CMUint32))
|
||||
|
||||
|
||||
typedef struct _SSMHelloRequest SSMHelloRequest;
|
||||
typedef struct _SSMHelloReply SSMHelloReply;
|
||||
typedef struct _SSMRequestSSLDataConnection SSMRequestSSLDataConnection;
|
||||
typedef struct _SSMReplySSLDataConnection SSMReplySSLDataConnection;
|
||||
typedef struct _SSMRequestSecurityStatus SSMRequestSecurityStatus;
|
||||
typedef struct _SSMReplySecurityStatus SSMReplySecurityStatus;
|
||||
|
||||
/*
|
||||
Functions to convert between an SSMString and a C string.
|
||||
Return values are allocated using PR_Malloc (which means that
|
||||
SSMPR_Free must be used to free up the memory after use).
|
||||
*/
|
||||
CMTStatus SSM_StringToSSMString(SSMString ** ssmString, int len, char * string);
|
||||
CMTStatus SSM_SSMStringToString(char ** string,int *len, SSMString * ssmString);
|
||||
|
||||
|
||||
#endif /* __PROTOCOL_H__ */
|
||||
2260
mozilla/security/psm/lib/protocol/protocolf.c
Normal file
2260
mozilla/security/psm/lib/protocol/protocolf.c
Normal file
File diff suppressed because it is too large
Load Diff
359
mozilla/security/psm/lib/protocol/protocolf.h
Normal file
359
mozilla/security/psm/lib/protocol/protocolf.h
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* 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 __PROTOCOLF_H__
|
||||
#define __PROTOCOLF_H__
|
||||
/*************************************************************************
|
||||
* For each type of message, parse and pack function is provided.
|
||||
*
|
||||
* Parse functions accept a ptr to the "blob" of data received from the
|
||||
* network and fill in fields of the message, numbers in host-order, strings
|
||||
* as C-style NULL-terminated strings. Return SSMPRStatus.
|
||||
*
|
||||
* Pack functions take all the info to construct a message and fill in a
|
||||
* ptr to the "blob" of data to be sent. Return length of the data blob, or
|
||||
* a zero in case of an error
|
||||
*
|
||||
* All functions set NSPR errors when necessary.
|
||||
************************************************************************/
|
||||
#include "protocol.h"
|
||||
#include "cert.h"
|
||||
|
||||
SSMPRStatus SSM_ParseHelloRequest(void * helloRequest,
|
||||
SSMPRUint32 * version,
|
||||
PRBool * doesUI,
|
||||
PRInt32 * policyType,
|
||||
SSMPRUint32 * profileLen,
|
||||
char ** profile);
|
||||
SSMPRInt32 SSM_PackHelloReply(void ** helloReply, SSMPRInt32 result,
|
||||
SSMPRUint32 sessionID, SSMPRUint32 version,
|
||||
SSMPRUint32 httpPort, SSMPRUint32 nonceLen,
|
||||
char * nonce, SSMPolicyType policy);
|
||||
|
||||
/* Parse data connections requests */
|
||||
SSMPRStatus SSM_ParseSSLDataConnectionRequest(void *sslRequest,
|
||||
SSMPRUint32 * flags,
|
||||
SSMPRUint32 * port,
|
||||
SSMPRUint32 * hostIPLen,
|
||||
char ** hostIP,
|
||||
SSMPRUint32 * hostNameLen,
|
||||
char ** hostName);
|
||||
SSMPRStatus SSM_ParseHashStreamRequest(void * hashStreamRequest,
|
||||
SSMPRUint32 * type);
|
||||
SSMPRStatus SSM_ParseP7EncodeConnectionRequest(void *request,
|
||||
SSMPRUint32 *ciRID);
|
||||
/* Messages to initiate PKCS7 data connection */
|
||||
/* PKCS7DecodeRequest message has no data */
|
||||
|
||||
/* Single data connection reply */
|
||||
SSMPRInt32 SSM_PackDataConnectionReply(void ** sslReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 connID,
|
||||
SSMPRUint32 port);
|
||||
|
||||
SSMPRStatus SSM_ParseSSLSocketStatusRequest(void * statusRequest,
|
||||
SSMPRUint32 * connID);
|
||||
SSMPRInt32 SSM_PackSSLSocketStatusReply(void ** statusReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
|
||||
/*
|
||||
* UI event is an asynchroneous message sent from PSM server to the client
|
||||
* NOTE: (context) is the actual context pointer, it is NOT a ptr-to-ptr.
|
||||
* The value of (context) is copied into the packet.
|
||||
*/
|
||||
SSMPRInt32 SSM_PackUIEvent(void ** eventRequest, SSMPRUint32 resourceID,
|
||||
SSMPRUint32 width, SSMPRUint32 height,
|
||||
SSMPRUint32 urlLen, char * url);
|
||||
|
||||
SSMPRInt32 SSM_PackTaskCompletedEvent(void **event, SSMPRUint32 resourceID,
|
||||
SSMPRUint32 numTasks, SSMPRUint32 result);
|
||||
|
||||
/* Verify raw signature */
|
||||
|
||||
SSMPRStatus SSM_ParseVerifyRawSigRequest(void * verifyRawSigRequest,
|
||||
SSMPRUint32 * algorithmID,
|
||||
SSMPRUint32 * paramsLen,
|
||||
unsigned char ** params,
|
||||
SSMPRUint32 * pubKeyLen,
|
||||
unsigned char ** pubKey,
|
||||
SSMPRUint32 * hashLen,
|
||||
unsigned char ** hash,
|
||||
SSMPRUint32 * signatureLen,
|
||||
unsigned char ** signature);
|
||||
SSMPRInt32 SSM_PackVerifyRawSigReply(void ** verifyRawSigReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* Verify detached signature */
|
||||
SSMPRStatus SSM_ParseVerifyDetachedSigRequest(void * request,
|
||||
SSMPRInt32 * pkcs7ContentID,
|
||||
SSMPRInt32 * certUsage,
|
||||
SSMPRInt32 * hashAlgID,
|
||||
SSMPRUint32 * keepCert,
|
||||
SSMPRUint32 * digestLen,
|
||||
unsigned char ** hash);
|
||||
|
||||
SSMPRInt32 SSM_PackVerifyDetachedSigReply(void ** verifyDetachedSigReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* PKCS#7 functions */
|
||||
SSMPRStatus SSM_ParseCreateSignedRequest(void *request,
|
||||
SSMPRInt32 *scertRID,
|
||||
SSMPRInt32 *ecertRID,
|
||||
SSMPRUint32 *dig_alg,
|
||||
SECItem **digest);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateSignedReply(void **reply, SSMPRInt32 ciRID,
|
||||
SSMPRUint32 result);
|
||||
|
||||
SSMPRStatus SSM_ParseCreateEncryptedRequest(void *request,
|
||||
SSMPRInt32 *scertRID,
|
||||
SSMPRInt32 *nrcerts,
|
||||
SSMPRInt32 **rcertRIDs);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateEncryptedReply(void **reply, SSMPRInt32 ciRID,
|
||||
SSMPRUint32 result);
|
||||
|
||||
/* Resource functions */
|
||||
SSMPRStatus SSM_ParseCreateResourceRequest(void *request,
|
||||
SSMPRUint32 *type,
|
||||
unsigned char **params,
|
||||
SSMPRUint32 *paramLen);
|
||||
|
||||
SSMPRStatus SSM_PackCreateResourceReply(void **reply, SSMPRStatus rv,
|
||||
SSMPRUint32 resID);
|
||||
|
||||
SSMPRStatus SSM_ParseGetAttribRequest(void * getAttribRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRUint32 * fieldID);
|
||||
|
||||
void SSM_DestroyAttrValue(SSMAttributeValue *value, PRBool freeit);
|
||||
|
||||
SSMPRInt32 SSM_PackGetAttribReply(void **getAttribReply,
|
||||
SSMPRInt32 result,
|
||||
SSMAttributeValue *value);
|
||||
SSMPRStatus SSM_ParseSetAttribRequest(SECItem *msg,
|
||||
SSMPRInt32 *resourceID,
|
||||
SSMPRInt32 *fieldID,
|
||||
SSMAttributeValue *value);
|
||||
/* Currently, there is no need for a pack version. There is nothing to send
|
||||
* back except for the notice that the operation was successful.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* Pickle and unpickle resources. */
|
||||
SSMPRStatus SSM_ParsePickleResourceRequest(void * pickleResourceRequest,
|
||||
SSMPRUint32 * resourceID);
|
||||
SSMPRInt32 SSM_PackPickleResourceReply(void ** pickleResourceReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceLen,
|
||||
void * resource);
|
||||
SSMPRStatus SSM_ParseUnpickleResourceRequest(void * unpickleResourceRequest,
|
||||
SSMPRUint32 blobSize,
|
||||
SSMPRUint32 * resourceType,
|
||||
SSMPRUint32 * resourceLen,
|
||||
void ** resource);
|
||||
SSMPRInt32 SSM_PackUnpickleResourceReply(void ** unpickleResourceReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
|
||||
/* Destroy resource */
|
||||
SSMPRStatus SSM_ParseDestroyResourceRequest(void * destroyResourceRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRUint32 * resourceType);
|
||||
SSMPRInt32 SSM_PackDestroyResourceReply(void ** destroyResourceReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* Duplicate resource */
|
||||
SSMPRStatus SSM_ParseDuplicateResourceRequest(void * request,
|
||||
SSMPRUint32 * resourceID);
|
||||
SSMPRInt32 SSM_PackDuplicateResourceReply(void ** reply, SSMPRInt32 result,
|
||||
SSMPRUint32 resID);
|
||||
|
||||
/* Cert actions */
|
||||
typedef struct MatchUserCertRequestData {
|
||||
PRUint32 certType;
|
||||
PRInt32 numCANames;
|
||||
char ** caNames;
|
||||
} MatchUserCertRequestData;
|
||||
|
||||
typedef struct SSMCertList {
|
||||
PRCList certs;
|
||||
PRInt32 count;
|
||||
} SSMCertList;
|
||||
|
||||
typedef struct SSMCertListElement {
|
||||
PRCList links;
|
||||
PRUint32 certResID;
|
||||
} SSMCertListElement;
|
||||
|
||||
#define SSM_CERT_LIST_ELEMENT_PTR(_q) (SSMCertListElement*)(_q);
|
||||
|
||||
SSMPRStatus SSM_ParseVerifyCertRequest(void * verifyCertRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRInt32 * certUsage);
|
||||
SSMPRInt32 SSM_PackVerifyCertReply(void ** verifyCertReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
SSMPRStatus SSM_ParseImportCertRequest(void * importCertRequest,
|
||||
SSMPRUint32 * blobLen,
|
||||
void ** certBlob);
|
||||
SSMPRInt32 SSM_PackImportCertReply(void ** importCertReply, SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByNicknameRequest(void *request, char ** nickname);
|
||||
PRInt32 SSM_PackFindCertByNicknameReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByKeyRequest(void *request, SECItem ** key);
|
||||
PRInt32 SSM_PackFindCertByKeyReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByEmailAddrRequest(void *request, char ** emailAddr);
|
||||
PRInt32 SSM_PackFindCertByEmailAddrReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseAddTempCertToDBRequest(void *request, PRUint32 *resourceID, char ** nickname, PRInt32 *ssl, PRInt32 *email, PRInt32 *objectSigning);
|
||||
PRInt32 SSM_PackAddTempCertToDBReply(void ** reply);
|
||||
PRStatus SSM_ParseMatchUserCertRequest(void *request, MatchUserCertRequestData** data);
|
||||
PRInt32 SSM_PackMatchUserCertReply(void **reply, SSMCertList * certList);
|
||||
|
||||
SSMPRInt32 SSM_PackErrorMessage(void ** errorReply, SSMPRInt32 result);
|
||||
|
||||
|
||||
/* PKCS11 actions */
|
||||
SSMPRStatus SSM_ParseKeyPairGenRequest(void *keyPairGenRequest,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 *keyPairCtxtID,
|
||||
SSMPRUint32 *genMechanism,
|
||||
SSMPRUint32 *keySize,
|
||||
unsigned char **params,
|
||||
SSMPRUint32 *paramLen);
|
||||
|
||||
SSMPRInt32 SSM_PackKeyPairGenResponse(void ** keyPairGenResponse,
|
||||
SSMPRUint32 keyPairId);
|
||||
|
||||
PRStatus
|
||||
SSM_ParseFinishKeyGenRequest(void *finishKeyGenRequest,
|
||||
PRInt32 requestLen,
|
||||
PRInt32 *keyGenContext);
|
||||
|
||||
/* CMMF/CRMF Actions */
|
||||
SSMPRStatus SSM_ParseCreateCRMFReqRequest(void *crmfReqRequest,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 *keyPairId);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateCRMFReqReply(void **crmfReqReply,
|
||||
SSMPRUint32 crmfReqId);
|
||||
|
||||
SSMPRStatus SSM_ParseEncodeCRMFReqRequest(void *encodeReq,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 **crmfReqId,
|
||||
SSMPRInt32 *numRequests);
|
||||
|
||||
SSMPRInt32 SSM_PackEncodeCRMFReqReply(void **encodeReply,
|
||||
char *crmfDER,
|
||||
SSMPRUint32 derLen);
|
||||
|
||||
SSMPRStatus SSM_ParseCMMFCertResponse(void *encodedRes,
|
||||
SSMPRInt32 encodeLen,
|
||||
char **nickname,
|
||||
char **base64Der,
|
||||
PRBool *doBackup);
|
||||
|
||||
PRStatus SSM_ParsePOPChallengeRequest(void *challenge,
|
||||
PRInt32 len,
|
||||
char **responseString);
|
||||
PRInt32 SSM_PackPOPChallengeResponse(void **response,
|
||||
char *responseString,
|
||||
PRInt32 responseStringLen);
|
||||
|
||||
PRInt32 SSM_PackPasswdRequest(void ** passwdRequest, PRInt32 tokenID,
|
||||
char * prompt, PRInt32 promptLen);
|
||||
PRStatus SSM_ParsePasswordReply(void * passwdReply, PRInt32 * result,
|
||||
PRInt32 * tokenID,
|
||||
char ** passwd, PRInt32 * passwdLen);
|
||||
|
||||
/* Sign Text Actions */
|
||||
typedef struct {
|
||||
char *stringToSign;
|
||||
char *hostName;
|
||||
char *caOption;
|
||||
PRInt32 numCAs;
|
||||
char **caNames;
|
||||
} signTextRequestData;
|
||||
|
||||
PRStatus SSM_ParseSignTextRequest(void* signTextRequest, PRInt32 len, PRUint32* resID, signTextRequestData ** data);
|
||||
|
||||
PRStatus SSM_ParseGetLocalizedTextRequest(void *data,
|
||||
SSMLocalizedString *whichString);
|
||||
|
||||
PRInt32 SSM_PackGetLocalizedTextResponse(void **data,
|
||||
SSMLocalizedString whichString,
|
||||
char *retString);
|
||||
|
||||
PRStatus SSM_ParseAddNewSecurityModuleRequest(void *data,
|
||||
char **moduleName,
|
||||
char **libraryPath,
|
||||
unsigned long *pubMechFlags,
|
||||
unsigned long *pubCipherFlags);
|
||||
|
||||
PRInt32 SSM_PackAddNewModuleResponse(void **data, PRInt32 rv);
|
||||
|
||||
PRStatus SSM_ParseDeleteSecurityModuleRequest(void *data, char **moduleName);
|
||||
|
||||
PRInt32 SSM_PackDeleteModuleResponse(void **data, PRInt32 moduleType);
|
||||
|
||||
PRInt32 SSM_PackFilePathRequest(void **data, PRInt32 resID, char *prompt,
|
||||
PRBool shouldFileExist, char *fileSuffix);
|
||||
|
||||
PRStatus SSM_ParseFilePathReply(void *message, char **filePath,
|
||||
PRInt32 *rid);
|
||||
|
||||
PRInt32 SSM_PackPromptRequestEvent(void **data, PRInt32 resID, char *prompt);
|
||||
PRStatus SSM_ParsePasswordPromptReply(void *data, PRInt32 *resID,
|
||||
char **reply);
|
||||
|
||||
/* messages for importing certs *the traditional way* */
|
||||
PRInt32 SSM_PackDecodeCertReply(void ** data, PRInt32 certID);
|
||||
PRStatus SSM_ParseDecodeCertRequest(void * data, PRInt32 * len,
|
||||
char ** buffer);
|
||||
PRStatus SSM_ParseGetKeyChoiceListRequest(void * data, PRUint32 dataLen,
|
||||
char ** type, PRUint32 *typeLen,
|
||||
char ** pqgString, PRUint32 *pqgLen);
|
||||
PRInt32 SSM_PackGetKeyChoiceListReply(void **data, char ** list);
|
||||
|
||||
PRStatus SSM_ParseGenKeyOldStyleRequest(void * data, PRUint32 datalen,
|
||||
char ** choiceString,
|
||||
char ** challenge,
|
||||
char ** typeString,
|
||||
char ** pqgString);
|
||||
PRInt32 SSM_PackGenKeyOldStyleReply(void ** data, char * keydata);
|
||||
|
||||
PRStatus SSM_ParseDecodeAndCreateTempCertRequest(void * data,
|
||||
char ** certbuf, PRUint32 * certlen, int * certClass);
|
||||
|
||||
#endif /*PROTOCOLF_H_*/
|
||||
74
mozilla/security/psm/lib/protocol/protocolnspr20.h
Normal file
74
mozilla/security/psm/lib/protocol/protocolnspr20.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 NULL
|
||||
#define NULL 0x00000000
|
||||
#endif
|
||||
|
||||
#define SSMPR_BYTES_PER_INT 4
|
||||
#define SSMPR_BYTES_PER_LONG 4
|
||||
|
||||
/******************************************************************
|
||||
* No NSPR - define all the SSMPR values and functions here
|
||||
******************************************************************
|
||||
*/
|
||||
|
||||
#define SSMPRStatus PRStatus
|
||||
#define SSMPR_SUCCESS PR_SUCCESS
|
||||
#define SSMPR_FAILURE PR_FAILURE
|
||||
|
||||
#define SSMPR_INVALID_ARGUMENT_ERROR PR_INVALID_ARGUMENT_ERROR
|
||||
#define SSMPR_OUT_OF_MEMORY_ERROR PR_OUT_OF_MEMORY_ERROR
|
||||
|
||||
#define SSMPRInt32 PRInt32
|
||||
#define SSMPRUint32 PRUint32
|
||||
|
||||
#define SSMPR_ntohl PR_ntohl
|
||||
#define SSMPR_htonl PR_htonl
|
||||
#define SSMPORT_Free PORT_Free
|
||||
#define SSMPORT_ZAlloc PORT_ZAlloc
|
||||
|
||||
#define SSMPR_SetError PR_SetError
|
||||
#define SSMPR_GetError PR_GetError
|
||||
#define SSMPORT_SetError PORT_SetError
|
||||
#define SSMPORT_GetError PORT_GetError
|
||||
|
||||
|
||||
|
||||
|
||||
49
mozilla/security/psm/lib/protocol/protocolport.c
Normal file
49
mozilla/security/psm/lib/protocol/protocolport.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*************************************************************************
|
||||
*
|
||||
* PSM portable run-time. (Used when NSPR20 is not available.)
|
||||
*
|
||||
*************************************************************************
|
||||
*/
|
||||
|
||||
SSMPRInt32 ssmprErrno;
|
||||
|
||||
void SSMPORT_SetError(SSMPRInt32 errorcode)
|
||||
{ ssmprErrno = errorcode; }
|
||||
|
||||
|
||||
SSMPRInt32 SSMPORT_GetError(void)
|
||||
{ return ssmprErrno; }
|
||||
|
||||
|
||||
93
mozilla/security/psm/lib/protocol/protocolport.h
Normal file
93
mozilla/security/psm/lib/protocol/protocolport.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 NULL
|
||||
#define NULL 0x00000000
|
||||
#endif
|
||||
|
||||
#define SSMPR_BYTES_PER_INT 4
|
||||
#define SSMPR_BYTES_PER_LONG 4
|
||||
|
||||
/******************************************************************
|
||||
* No NSPR - define all the SSMPR values and functions here
|
||||
******************************************************************
|
||||
*/
|
||||
|
||||
typedef enum { SSMPR_SUCCESS = 0, SSMPR_FAILURE = -1 } SSMPRStatus;
|
||||
enum {
|
||||
SSMPR_INVALID_ARGUMENT_ERROR = -6000,
|
||||
SSMPR_OUT_OF_MEMORY_ERROR = -5987
|
||||
};
|
||||
|
||||
#if SSMPR_BYTES_PER_INT == 4
|
||||
typedef unsigned int SSMPRUint32;
|
||||
typedef int SSMPRInt32;
|
||||
#elif SSMPR_BYTES_PER_LONG == 4
|
||||
typedef unsigned long SSMPRUint32;
|
||||
typedef long SSMPRInt32;
|
||||
#else
|
||||
#error No suitable type for SSMPRInt32/SSMPRUint32
|
||||
#endif
|
||||
|
||||
/*******************************************************************
|
||||
* Use libc functions instead
|
||||
*******************************************************************
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#define SSMPR_ntohl ntohl
|
||||
#define SSMPR_htonl htonl
|
||||
|
||||
#include <stdlib.h>
|
||||
#define SSMPORT_Free free
|
||||
#define SSMPR_sprint printf
|
||||
#define SSMPORT_ZAlloc malloc
|
||||
|
||||
extern SSMPRInt32 ssmprErrno;
|
||||
#define SSMPR_SetError(x, y) SSMPORT_SetError(x)
|
||||
#define SSMPR_GetError SSMPORT_GetError
|
||||
void SSMPORT_SetError(SSMPRInt32 errorcode);
|
||||
|
||||
|
||||
|
||||
|
||||
169
mozilla/security/psm/lib/protocol/protocolshr.c
Normal file
169
mozilla/security/psm/lib/protocol/protocolshr.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "string.h"
|
||||
#include "protocol.h"
|
||||
#include "protocolshr.h"
|
||||
#include "messages.h"
|
||||
|
||||
/* Forward ref */
|
||||
static void encrypt(CMTItem *data);
|
||||
static void decrypt(CMTItem *data);
|
||||
|
||||
const char *kPrefix = "Encrypted";
|
||||
|
||||
/* encryption request */
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
EncryptRequestMessage request;
|
||||
EncryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.keyid.data = 0;
|
||||
request.data.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode incoming message */
|
||||
rv = CMT_DecodeMessage(EncryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser; /* Protocol error */
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Encrypt" by prefixing the data */
|
||||
reply.item.len = request.data.len + pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (pLen) memcpy(reply.item.data, kPrefix, pLen);
|
||||
encrypt(&request.data);
|
||||
memcpy(&reply.item.data[pLen], request.data.data, request.data.len);
|
||||
|
||||
/* Generate response */
|
||||
message->type = SSM_SDR_ENCRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(EncryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser; /* Unknown error */
|
||||
|
||||
loser:
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* decryption request */
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
DecryptRequestMessage request;
|
||||
DecryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.data.data = 0;
|
||||
request.ctx.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode the message */
|
||||
rv = CMT_DecodeMessage(DecryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Decrypt" the message by removing the key */
|
||||
if (pLen && memcmp(request.data.data, kPrefix, pLen) != 0) {
|
||||
rv = CMTFailure; /* Invalid format */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
reply.item.len = request.data.len - pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) { rv = CMTFailure; goto loser; }
|
||||
|
||||
memcpy(reply.item.data, &request.data.data[pLen], reply.item.len);
|
||||
decrypt(&reply.item);
|
||||
|
||||
/* Create reply message */
|
||||
message->type = SSM_SDR_DECRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(DecryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
loser:
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* "encrypt" */
|
||||
static unsigned char mask[64] = {
|
||||
0x73, 0x46, 0x1a, 0x05, 0x24, 0x65, 0x43, 0xb4, 0x24, 0xee, 0x79, 0xc1, 0xcc,
|
||||
0x49, 0xc7, 0x27, 0x11, 0x91, 0x2e, 0x8f, 0xaa, 0xf7, 0x62, 0x75, 0x41, 0x7e,
|
||||
0xb2, 0x42, 0xde, 0x1b, 0x42, 0x7b, 0x1f, 0x33, 0x49, 0xca, 0xd1, 0x6a, 0x85,
|
||||
0x05, 0x6c, 0xf9, 0x0e, 0x3e, 0x72, 0x02, 0xf2, 0xd8, 0x9d, 0xa1, 0xb8, 0x6e,
|
||||
0x03, 0x18, 0x3e, 0x82, 0x86, 0x34, 0x1a, 0x61, 0xd9, 0x65, 0xb6, 0x7f
|
||||
};
|
||||
|
||||
static void
|
||||
encrypt(CMTItem *data)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
j = 0;
|
||||
for(i = 0;i < data->len;i++)
|
||||
{
|
||||
data->data[i] ^= mask[j];
|
||||
|
||||
if (++j >= 64) j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
decrypt(CMTItem *data)
|
||||
{
|
||||
encrypt(data);
|
||||
}
|
||||
|
||||
|
||||
48
mozilla/security/psm/lib/protocol/protocolshr.h
Normal file
48
mozilla/security/psm/lib/protocol/protocolshr.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*
|
||||
protocolshr.h - Definitions of shared routines for both client and server
|
||||
These are mostly for testing.
|
||||
*/
|
||||
|
||||
#ifndef __PROTOCOLSHR_H__
|
||||
#define __PROTOCOLSHR_H__
|
||||
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message);
|
||||
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *meessage);
|
||||
|
||||
|
||||
#endif /* __PROTOCOLSHR_H__ */
|
||||
207
mozilla/security/psm/lib/protocol/protocoltest.c
Normal file
207
mozilla/security/psm/lib/protocol/protocoltest.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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 "protocolf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
void * blob, * recvd;
|
||||
int blobSize;
|
||||
SSMPRUint32 version, flags, port, connID, keySize, secretKeySize;
|
||||
SSMPRUint32 sessionID, httpPort;
|
||||
SSMPRInt32 result;
|
||||
char *profile, * nonce, * hostIP, * hostName, * cipher, * CA;
|
||||
SSMPRStatus rv;
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to pack and parse HelloRequest message
|
||||
*/
|
||||
version = 3;
|
||||
profile = (char *)SSMPORT_ZAlloc(strlen("profile"));
|
||||
sprintf(profile, "profile");
|
||||
printf("HelloRequest, packing version #%d, profile %s\n",
|
||||
version, profile);
|
||||
blobSize = SSM_PackHelloRequest(&blob, version, profile);
|
||||
if (!blobSize)
|
||||
printf("Error in PackHelloRequest: %d\n", SSMPR_GetError());
|
||||
SSMPORT_Free(profile);
|
||||
version = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseHelloRequest(recvd, &version, &profile);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseHelloRequest: %d\n", SSMPR_GetError());
|
||||
printf("HelloRequest, parsing version #%d, profile %s\n",
|
||||
version, profile);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack HelloReply message
|
||||
*/
|
||||
version = 5;
|
||||
result = 2;
|
||||
sessionID = 34567;
|
||||
httpPort = 87654;
|
||||
nonce = (char *)SSMPORT_ZAlloc(strlen("some secret nonce"));
|
||||
sprintf(nonce, "some secret nonce");
|
||||
printf("HelloReply, packing result %d, sessionID %d, version #%d, httpPort %d,\n nonce %s\n",
|
||||
result, sessionID, version, httpPort, nonce);
|
||||
blobSize = SSM_PackHelloReply(&blob, result, sessionID, version, httpPort,
|
||||
nonce);
|
||||
if (!blobSize)
|
||||
printf("Error in PackHelloReply: %d\n", SSMPR_GetError());
|
||||
memset(nonce, 0, strlen(nonce));
|
||||
SSMPORT_Free(nonce);
|
||||
version = result = sessionID = httpPort = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseHelloReply(recvd, &result, &sessionID, &version, &httpPort,
|
||||
&nonce);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseHelloReply: %d\n", SSMPR_GetError());
|
||||
printf("HelloReply, parsing result %d, sessionID %d, version #%d, httpPort %d, \n nonce %s\n",
|
||||
result, sessionID, version, httpPort, nonce);
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SSLDataConnectionRequest message
|
||||
*/
|
||||
flags = 0x00044000;
|
||||
port = 34567;
|
||||
hostIP = (char *)SSMPORT_ZAlloc(strlen("somehostIP"));
|
||||
sprintf(hostIP, "somehostIP");
|
||||
hostName = (char *)SSMPORT_ZAlloc(strlen("somehostName"));
|
||||
sprintf(hostName, "somehostName");
|
||||
printf("SSLDataConnRequest, packing flags %x, port %d, hostIP %s, hostName %s\n",
|
||||
flags, port, hostIP, hostName);
|
||||
blobSize = SSM_PackSSLDataConnectionRequest(&blob, flags, port, hostIP,
|
||||
hostName);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSSLDataConnectionRequest: %d\n", SSMPR_GetError());
|
||||
SSMPORT_Free(hostIP);
|
||||
SSMPORT_Free(hostName);
|
||||
flags = port = 0;
|
||||
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
|
||||
rv = SSM_ParseSSLDataConnectionRequest(recvd, &flags, &port, &hostIP,
|
||||
&hostName);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSSLDataConnectionRequest: %d\n", SSMPR_GetError());
|
||||
printf(
|
||||
"SSLDataConnRequest, parsing flags %x, port %d, hostIP %s, hostName %s\n",
|
||||
flags, port, hostIP, hostName);
|
||||
SSMPORT_Free(hostIP);
|
||||
SSMPORT_Free(hostName);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SSLDataConnectionReply message
|
||||
*/
|
||||
result = 2;
|
||||
connID = 713259;
|
||||
port = 57402;
|
||||
printf("SSLDataConnReply, packing result %d, connectionID %d, port %d\n",
|
||||
result, connID, port);
|
||||
blobSize = SSM_PackSSLDataConnectionReply(&blob, result, connID, port);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSSLDataConnReply: %d\n", SSMPR_GetError());
|
||||
result = connID = port = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSSLDataConnectionReply(recvd, &result, &connID, &port);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSSLDataConnectionReply: %d\n", SSMPR_GetError());
|
||||
printf("SSLDataConnReply, parsing result %d, connectionID %d, port %d\n",
|
||||
result, connID, port);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SecurityStatusRequest message
|
||||
*/
|
||||
connID = 45375;
|
||||
printf("SecurityStatusRequest, packing connection ID %d\n", connID);
|
||||
blobSize = SSM_PackSecurityStatusRequest(&blob, connID);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSecurityStatusRequest: %d\n", SSMPR_GetError());
|
||||
connID = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSecurityStatusRequest(recvd, &connID);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSecurityStatusRequest: %d\n", SSMPR_GetError());
|
||||
printf("SecurityStatusRequest, parsing connection ID %d\n", connID);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SecurityStatusReply message
|
||||
*/
|
||||
result = 2;
|
||||
keySize = 256;
|
||||
secretKeySize = 511;
|
||||
cipher = (char *)SSMPORT_ZAlloc(strlen("My Cipher"));
|
||||
sprintf(cipher, "My Cipher");
|
||||
CA = (char *)SSMPORT_ZAlloc(strlen("My CA issuer"));
|
||||
sprintf(CA, "My CA issuer");
|
||||
printf("SecurityStatusReply, packing result %d, keysize %d, secretKeySize %d, cipher %s, CA %s\n", result, keySize, secretKeySize, cipher, CA);
|
||||
blobSize = SSM_PackSecurityStatusReply(&blob, result, keySize, secretKeySize, cipher, CA);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSecurityStatusReply: %d\n", SSMPR_GetError());
|
||||
result = keySize = secretKeySize = 0;
|
||||
SSMPORT_Free(cipher);
|
||||
SSMPORT_Free(CA);
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSecurityStatusReply(recvd, &result, &keySize, &secretKeySize,
|
||||
&cipher, &CA);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSecurityStatusReply: %d\n", SSMPR_GetError());
|
||||
printf("SecurityStatusReply, parsing result %d, keysize %d, secretKeySize %d, cipher %s, CA %s\n", result, keySize, secretKeySize, cipher, CA);
|
||||
}
|
||||
|
||||
|
||||
|
||||
130
mozilla/security/psm/lib/protocol/protocolutil.c
Normal file
130
mozilla/security/psm/lib/protocol/protocolutil.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 "protocol.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef NSPR20
|
||||
#include "protocolport.c"
|
||||
#endif
|
||||
|
||||
CMStatus SSM_SSMStringToString(char ** string,
|
||||
int *len,
|
||||
SSMString * ssmString)
|
||||
{
|
||||
char * str = NULL;
|
||||
int realLen;
|
||||
PRStatus rv =PR_SUCCESS;
|
||||
|
||||
if (!ssmString || !string ) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* in case we fail */
|
||||
*string = NULL;
|
||||
if (len) *len = 0;
|
||||
|
||||
/* Convert from net byte order */
|
||||
realLen = SSMPR_ntohl(ssmString->m_length);
|
||||
|
||||
str = (char *)PR_CALLOC(realLen+1); /* add 1 byte for end 0 */
|
||||
if (!str) {
|
||||
rv = PR_OUT_OF_MEMORY_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
memcpy(str, (char *) &(ssmString->m_data), realLen);
|
||||
/* str[realLen]=0; */
|
||||
|
||||
if (len) *len = realLen;
|
||||
*string = str;
|
||||
return rv;
|
||||
|
||||
loser:
|
||||
if (str)
|
||||
PR_Free(str);
|
||||
if (string && *string) {
|
||||
PR_Free(*string);
|
||||
*string = NULL;
|
||||
}
|
||||
if (rv == PR_SUCCESS)
|
||||
rv = PR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
CMStatus SSM_StringToSSMString(SSMString ** ssmString, int length,
|
||||
char * string)
|
||||
{
|
||||
SSMPRUint32 len;
|
||||
SSMString *result = NULL;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
|
||||
if (!string || !ssmString) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ssmString = NULL; /* in case we fail */
|
||||
|
||||
if (length) len = length;
|
||||
else len = strlen(string);
|
||||
if (len <= 0) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
result = (SSMString *) PR_CALLOC(sizeof(PRUint32) +
|
||||
SSMSTRING_PADDED_LENGTH(len));
|
||||
if (!result) {
|
||||
rv = PR_OUT_OF_MEMORY_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
result->m_length = SSMPR_htonl(len);
|
||||
memcpy((char *) (&(result->m_data)), string, len);
|
||||
|
||||
*ssmString = result;
|
||||
goto done;
|
||||
|
||||
loser:
|
||||
if (result)
|
||||
PR_Free(result);
|
||||
*ssmString = NULL;
|
||||
if (rv == PR_SUCCESS)
|
||||
rv = PR_FAILURE;
|
||||
done:
|
||||
return rv;
|
||||
}
|
||||
|
||||
165
mozilla/security/psm/lib/protocol/rsrcids.h
Normal file
165
mozilla/security/psm/lib/protocol/rsrcids.h
Normal file
@@ -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
|
||||
324
mozilla/security/psm/lib/protocol/ssmdefs.h
Normal file
324
mozilla/security/psm/lib/protocol/ssmdefs.h
Normal file
@@ -0,0 +1,324 @@
|
||||
/* -*- 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. */
|
||||
typedef long CMInt32;
|
||||
typedef unsigned long CMUint32;
|
||||
typedef long SSMResourceID;
|
||||
|
||||
typedef int SSMStatus;
|
||||
|
||||
#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 */
|
||||
#define SSM_REQUEST_MESSAGE 0x10000000
|
||||
#define SSM_REPLY_OK_MESSAGE 0x20000000
|
||||
#define SSM_REPLY_ERR_MESSAGE 0x30000000
|
||||
#define SSM_EVENT_MESSAGE 0x40000000
|
||||
|
||||
/* Message types */
|
||||
#define SSM_DATA_CONNECTION 0x00001000
|
||||
#define SSM_OBJECT_SIGNING 0x00002000
|
||||
#define SSM_RESOURCE_ACTION 0x00003000
|
||||
#define SSM_CERT_ACTION 0x00004000
|
||||
#define SSM_PKCS11_ACTION 0x00005000
|
||||
#define SSM_CRMF_ACTION 0x00006000
|
||||
#define SSM_FORMSIGN_ACTION 0x00007000
|
||||
#define SSM_LOCALIZED_TEXT 0x00008000
|
||||
#define SSM_HELLO_MESSAGE 0x00009000
|
||||
#define SSM_SECURITY_ADVISOR 0x0000a000
|
||||
#define SSM_SEC_CFG_ACTION 0x0000b000
|
||||
#define SSM_KEYGEN_TAG 0x0000c000
|
||||
#define SSM_PREF_ACTION 0x0000d000
|
||||
#define SSM_MISC_ACTION 0x0000f000
|
||||
|
||||
/* Data connection messages subtypes */
|
||||
#define SSM_SSL_CONNECTION 0x00000100
|
||||
#define SSM_PKCS7DECODE_STREAM 0x00000200
|
||||
#define SSM_PKCS7ENCODE_STREAM 0x00000300
|
||||
#define SSM_HASH_STREAM 0x00000400
|
||||
#define SSM_TLS_CONNECTION 0x00000500
|
||||
#define SSM_PROXY_CONNECTION 0x00000600
|
||||
|
||||
/* Object signing message subtypes */
|
||||
#define SSM_VERIFY_RAW_SIG 0x00000100
|
||||
#define SSM_VERIFY_DETACHED_SIG 0x00000200
|
||||
#define SSM_CREATE_SIGNED 0x00000300
|
||||
#define SSM_CREATE_ENCRYPTED 0x00000400
|
||||
|
||||
/* Resource access messages subtypes */
|
||||
#define SSM_CREATE_RESOURCE 0x00000100
|
||||
#define SSM_DESTROY_RESOURCE 0x00000200
|
||||
#define SSM_GET_ATTRIBUTE 0x00000300
|
||||
#define SSM_CONSERVE_RESOURCE 0x00000400
|
||||
#define SSM_DUPLICATE_RESOURCE 0x00000500
|
||||
#define SSM_SET_ATTRIBUTE 0x00000600
|
||||
#define SSM_TLS_STEPUP 0x00000700
|
||||
#define SSM_PROXY_STEPUP 0x00000800
|
||||
|
||||
/* Further specification for resource access messages */
|
||||
#define SSM_SSLSocket_Status 0x00000010
|
||||
|
||||
#define SSM_NO_ATTRIBUTE 0x00000000
|
||||
#define SSM_NUMERIC_ATTRIBUTE 0x00000010
|
||||
#define SSM_STRING_ATTRIBUTE 0x00000020
|
||||
#define SSM_RID_ATTRIBUTE 0x00000030
|
||||
|
||||
#define SSM_PICKLE_RESOURCE 0x00000010
|
||||
#define SSM_UNPICKLE_RESOURCE 0x00000020
|
||||
#define SSM_PICKLE_SECURITY_STATUS 0x00000030
|
||||
|
||||
/* Certificate access message subtypes */
|
||||
#define SSM_IMPORT_CERT 0x00000100
|
||||
#define SSM_VERIFY_CERT 0x00000200
|
||||
#define SSM_FIND_BY_NICKNAME 0x00000300
|
||||
#define SSM_FIND_BY_KEY 0x00000400
|
||||
#define SSM_FIND_BY_EMAILADDR 0x00000500
|
||||
#define SSM_ADD_TO_DB 0x00000600
|
||||
#define SSM_DECODE_CERT 0x00000700
|
||||
#define SSM_MATCH_USER_CERT 0x00000800
|
||||
#define SSM_DESTROY_CERT 0x00000900
|
||||
#define SSM_DECODE_TEMP_CERT 0x00000a00
|
||||
#define SSM_REDIRECT_COMPARE 0x00000b00
|
||||
#define SSM_DECODE_CRL 0x00000c00
|
||||
#define SSM_EXTENSION_VALUE 0x00000d00
|
||||
#define SSM_HTML_INFO 0x00000e00
|
||||
|
||||
/* message subtypes used for KEYGEN form tag */
|
||||
#define SSM_GET_KEY_CHOICE 0x00000100
|
||||
#define SSM_KEYGEN_START 0x00000200
|
||||
#define SSM_KEYGEN_TOKEN 0x00000300
|
||||
#define SSM_KEYGEN_PASSWORD 0x00000400
|
||||
#define SSM_KEYGEN_DONE 0x00000500
|
||||
|
||||
#define SSM_CREATE_KEY_PAIR 0x00000100
|
||||
#define SSM_FINISH_KEY_GEN 0x00000200
|
||||
#define SSM_ADD_NEW_MODULE 0x00000300
|
||||
#define SSM_DEL_MODULE 0x00000400
|
||||
#define SSM_LOGOUT_ALL 0x00000500
|
||||
#define SSM_ENABLED_CIPHERS 0x00000600
|
||||
|
||||
#define SSM_CREATE_CRMF_REQ 0x00000100
|
||||
#define SSM_DER_ENCODE_REQ 0x00000200
|
||||
#define SSM_PROCESS_CMMF_RESP 0x00000300
|
||||
#define SSM_CHALLENGE 0x00000400
|
||||
|
||||
#define SSM_SIGN_TEXT 0x00000100
|
||||
|
||||
/* Security Config subtypes */
|
||||
#define SSM_ADD_CERT_TO_TEMP_DB 0x00000100
|
||||
#define SSM_ADD_TEMP_CERT_TO_DB 0x00000200
|
||||
#define SSM_DELETE_PERM_CERTS 0x00000300
|
||||
#define SSM_FIND_CERT_KEY 0x00000400
|
||||
#define SSM_GET_CERT_PROP_BY_KEY 0x00000500
|
||||
#define SSM_CERT_INDEX_ENUM 0x00000600
|
||||
|
||||
/* subcategories for SSM_FIND_CERT_KEY and SSM_CERT_INDEX_ENUM */
|
||||
#define SSM_FIND_KEY_BY_NICKNAME 0x00000010
|
||||
#define SSM_FIND_KEY_BY_EMAIL_ADDR 0x00000020
|
||||
#define SSM_FIND_KEY_BY_DN 0x00000030
|
||||
|
||||
/* subcategories for SSM_GET_CERT_PROP_BY_KEY */
|
||||
#define SSM_SECCFG_GET_NICKNAME 0x00000010
|
||||
#define SSM_SECCFG_GET_EMAIL_ADDR 0x00000020
|
||||
#define SSM_SECCFG_GET_DN 0x00000030
|
||||
#define SSM_SECCFG_GET_TRUST 0x00000040
|
||||
#define SSM_SECCFG_CERT_IS_PERM 0x00000050
|
||||
#define SSM_SECCFG_GET_NOT_BEFORE 0x00000060
|
||||
#define SSM_SECCFG_GET_NOT_AFTER 0x00000070
|
||||
#define SSM_SECCFG_GET_SERIAL_NO 0x00000080
|
||||
#define SSM_SECCFG_GET_ISSUER 0x00000090
|
||||
#define SSM_SECCFG_GET_ISSUER_KEY 0x000000a0
|
||||
#define SSM_SECCFG_GET_SUBJECT_NEXT 0x000000b0
|
||||
#define SSM_SECCFG_GET_SUBJECT_PREV 0x000000c0
|
||||
|
||||
/* Misc requests */
|
||||
#define SSM_MISC_GET_RNG_DATA 0x00000100
|
||||
#define SSM_MISC_PUT_RNG_DATA 0x00000200
|
||||
#define SSM_MISC_SDR_ENCRYPT 0x00000300
|
||||
#define SSM_MISC_SDR_DECRYPT 0x00000400
|
||||
#define SSM_MISC_UI 0x00000500
|
||||
|
||||
/* specific UI requests */
|
||||
#define SSM_UI_CHANGE_PASSWORD 0x00000010
|
||||
|
||||
#define SSM_SDR_ENCRYPT_REQUEST \
|
||||
(SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_ENCRYPT)
|
||||
#define SSM_SDR_ENCRYPT_REPLY \
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_ENCRYPT)
|
||||
#define SSM_SDR_DECRYPT_REQUEST \
|
||||
(SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_DECRYPT)
|
||||
#define SSM_SDR_DECRYPT_REPLY \
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_DECRYPT)
|
||||
|
||||
/* Type masks for message types */
|
||||
#define SSM_CATEGORY_MASK 0xF0000000
|
||||
#define SSM_TYPE_MASK 0x0000F000
|
||||
#define SSM_SUBTYPE_MASK 0x00000F00
|
||||
#define SSM_SPECIFIC_MASK 0x000000F0
|
||||
|
||||
typedef struct SSMAttributeValue {
|
||||
CMUint32 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 */
|
||||
#define SSM_UI_EVENT 0x00001000
|
||||
#define SSM_TASK_COMPLETED_EVENT 0x00002000
|
||||
#define SSM_FILE_PATH_EVENT 0x00003000
|
||||
#define SSM_PROMPT_EVENT 0x00004000
|
||||
#define SSM_AUTH_EVENT 0x00007000
|
||||
#define SSM_SAVE_PREF_EVENT 0x00008000
|
||||
#define SSM_MISC_EVENT 0x0000f000
|
||||
|
||||
/* Flags used in Create SSL Data request */
|
||||
#define SSM_REQUEST_SSL_DATA_SSL 0x00000001
|
||||
#define SSM_REQUEST_SSL_DATA_PROXY 0x00000002
|
||||
#define SSM_REQUEST_SSL_CONNECTION_MASK 0x00000003
|
||||
|
||||
/* Create typedefs for the various #defines */
|
||||
typedef CMUint32 SSMMessageCategory;
|
||||
typedef CMUint32 SSMMessageType;
|
||||
typedef CMUint32 SSMDataConnectionSType;
|
||||
typedef CMUint32 SSMObjSignSType;
|
||||
typedef CMUint32 SSMResourceAccessSType;
|
||||
typedef CMUint32 SSMCreateResource;
|
||||
typedef CMUint32 SSMResourceAttrType;
|
||||
typedef CMUint32 SSMResourceConsv;
|
||||
typedef CMUint32 SSMCertAccessSType;
|
||||
typedef CMUint32 SSMKeyGenTagProcessType;
|
||||
typedef CMUint32 SSMPKCS11Actions;
|
||||
typedef CMUint32 SSMCRMFAction;
|
||||
typedef CMUint32 SSMFormSignAction;
|
||||
typedef CMUint32 SSMSecCfgAction;
|
||||
typedef CMUint32 SSMSecCfgFindByType;
|
||||
typedef CMUint32 SSMSecCfgGetCertPropType;
|
||||
typedef CMUint32 SSMMiscRequestType;
|
||||
typedef CMUint32 SSMMessageMaskType;
|
||||
typedef CMUint32 SSMEventType;
|
||||
typedef CMUint32 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__ */
|
||||
628
mozilla/security/psm/lib/protocol/templates.c
Normal file
628
mozilla/security/psm/lib/protocol/templates.c
Normal file
@@ -0,0 +1,628 @@
|
||||
/* -*- 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_BOOL, offsetof(UIEvent, isModal) },
|
||||
{ CMT_DT_STRING, offsetof(UIEvent, url) },
|
||||
{ CMT_DT_ITEM, offsetof(UIEvent, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/*
|
||||
* The old UI Event was missing the modal indication.
|
||||
* As a transition aid, we use the old template if the
|
||||
* "modern" version doesn't work. Model is true in that case
|
||||
*/
|
||||
CMTMessageTemplate OldUIEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UIEvent, resourceID) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, width) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, height) },
|
||||
{ CMT_DT_STRING, offsetof(UIEvent, url) },
|
||||
{ CMT_DT_ITEM, offsetof(UIEvent, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TaskCompletedEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, resourceID) },
|
||||
{ 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 }
|
||||
};
|
||||
|
||||
CMTMessageTemplate EncryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, keyid) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, data) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, ctx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(DecryptRequestMessage, data) },
|
||||
{ CMT_DT_ITEM, offsetof(DecryptRequestMessage, ctx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
</IfModule>
|
||||
@@ -1,25 +0,0 @@
|
||||
SERVER REQUIREMENTS
|
||||
- Apache 1.3 or higher with mod_rewrite enabled
|
||||
- PHP 4.3.2 or higher
|
||||
- CakePHP 1.1.7.3363 or higher
|
||||
- MySQL (preferred) or PostgreSQL
|
||||
|
||||
INSTALLATION:
|
||||
- All files accompanying this README should be placed into the /app directory of
|
||||
your CakePHP install. Once complete, you should have a directory structure similar
|
||||
to the following where (/) is the base of your domain:
|
||||
/
|
||||
app/
|
||||
config/
|
||||
controllers/
|
||||
models/
|
||||
webroot/
|
||||
...
|
||||
cake/
|
||||
vendors/
|
||||
|
||||
- Import the database schema (/app/config/dist.sql) into your database
|
||||
- Rename database.dist.php to database.php and edit the file to reflect your
|
||||
database configuration
|
||||
- Rename bootstrap.dist.php to bootstrap.php and follow the editing instructions
|
||||
within. All fields except APP_* and MAX_YEAR are optional.
|
||||
@@ -1,4 +0,0 @@
|
||||
<?php
|
||||
class AppController extends Controller {
|
||||
}
|
||||
?>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?php
|
||||
class AppModel extends Model {
|
||||
}
|
||||
?>
|
||||
@@ -1,76 +0,0 @@
|
||||
;<?php die() ?>
|
||||
; SVN FILE: $Id: acl.ini.php,v 1.3 2006-10-08 03:39:21 reed%reedloden.com Exp $
|
||||
;/**
|
||||
; * Short description for file.
|
||||
; *
|
||||
; *
|
||||
; * PHP versions 4 and 5
|
||||
; *
|
||||
; * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
; * Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * 1785 E. Sahara Avenue, Suite 490-204
|
||||
; * Las Vegas, Nevada 89104
|
||||
; *
|
||||
; * Licensed under The MIT License
|
||||
; * Redistributions of files must retain the above copyright notice.
|
||||
; *
|
||||
; * @filesource
|
||||
; * @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
; * @package cake
|
||||
; * @subpackage cake.app.config
|
||||
; * @since CakePHP v 0.10.0.1076
|
||||
; * @version $Revision: 1.3 $
|
||||
; * @modifiedby $LastChangedBy: phpnut $
|
||||
; * @lastmodified $Date: 2006-10-08 03:39:21 $
|
||||
; * @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
; */
|
||||
|
||||
; acl.ini.php - Cake ACL Configuration
|
||||
; ---------------------------------------------------------------------
|
||||
; Use this file to specify user permissions.
|
||||
; aco = access control object (something in your application)
|
||||
; aro = access request object (something requesting access)
|
||||
;
|
||||
; User records are added as follows:
|
||||
;
|
||||
; [uid]
|
||||
; groups = group1, group2, group3
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; Group records are added in a similar manner:
|
||||
;
|
||||
; [gid]
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; The allow, deny, and groups sections are all optional.
|
||||
; NOTE: groups names *cannot* ever be the same as usernames!
|
||||
;
|
||||
; ACL permissions are checked in the following order:
|
||||
; 1. Check for user denies (and DENY if specified)
|
||||
; 2. Check for user allows (and ALLOW if specified)
|
||||
; 3. Gather user's groups
|
||||
; 4. Check group denies (and DENY if specified)
|
||||
; 5. Check group allows (and ALLOW if specified)
|
||||
; 6. If no aro, aco, or group information is found, DENY
|
||||
;
|
||||
; ---------------------------------------------------------------------
|
||||
|
||||
;-------------------------------------
|
||||
;Users
|
||||
;-------------------------------------
|
||||
|
||||
[username-goes-here]
|
||||
groups = group1, group2
|
||||
deny = aco1, aco2
|
||||
allow = aco3, aco4
|
||||
|
||||
;-------------------------------------
|
||||
;Groups
|
||||
;-------------------------------------
|
||||
|
||||
[groupname-goes-here]
|
||||
deny = aco5, aco6
|
||||
allow = aco7, aco8
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/* REQUIRED - APP_NAME is used on all <title>s and mail names/subjects. APP_BASE
|
||||
* should be a FQDN with protocol minus the trailing slash e.g. http://example.tld/party
|
||||
*/
|
||||
define('APP_NAME', '');
|
||||
define('APP_EMAIL', '');
|
||||
define('APP_BASE', '');
|
||||
|
||||
/* You should specify a Google Map API key here. Without it, all mapping features
|
||||
* will be disabled. To obtain a key, visit http://www.google.com/apis/maps/
|
||||
*/
|
||||
define('GMAP_API_KEY', '');
|
||||
|
||||
/* The search API key is used to generate spelling suggestions for locations not
|
||||
* not found during a Geocode operation. You may obtain a key here: http://code.google.com/apis/soapsearch/
|
||||
*/
|
||||
define('GSEARCH_API_KEY', '');
|
||||
|
||||
/* The maximum year shown for party registrations */
|
||||
define('MAX_YEAR', 2007);
|
||||
|
||||
/* The Flickr API is used to show photos of each party on the individual party
|
||||
* pages and home page. See http://flickr.com/services/api/keys/ to obtain a key
|
||||
*/
|
||||
define('FLICKR_API_KEY', '');
|
||||
|
||||
/* The tag prefix is used to limit the results returned to a specific party.
|
||||
* e.g. any photo tagged with FirefoxParty11 will be shown on party 11's page.
|
||||
* Photos tagged with only the prefix are shown on the front page (so choose wisely! ;) ).
|
||||
*/
|
||||
define('FLICKR_TAG_PREFIX', '');
|
||||
?>
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: core.php,v 1.4 2006-10-08 03:39:21 reed%reedloden.com Exp $ */
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.4 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-10-08 03:39:21 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* If you do not have mod rewrite on your system
|
||||
* or if you prefer to use CakePHP pretty urls.
|
||||
* uncomment the line below.
|
||||
* Note: If you do have mod rewrite but prefer the
|
||||
* CakePHP pretty urls, you also have to remove the
|
||||
* .htaccess files
|
||||
* release/.htaccess
|
||||
* release/app/.htaccess
|
||||
* release/app/webroot/.htaccess
|
||||
*/
|
||||
// define ('BASE_URL', env('SCRIPT_NAME'));
|
||||
/**
|
||||
* Set debug level here:
|
||||
* - 0: production
|
||||
* - 1: development
|
||||
* - 2: full debug with sql
|
||||
* - 3: full debug with sql and dump of the current object
|
||||
*
|
||||
* In production, the "flash messages" redirect after a time interval.
|
||||
* With the other debug levels you get to click the "flash message" to continue.
|
||||
*
|
||||
*/
|
||||
define('DEBUG', 0);
|
||||
/**
|
||||
* Turn of caching checking wide.
|
||||
* You must still use the controller var cacheAction inside you controller class.
|
||||
* You can either set it controller wide, or in each controller method.
|
||||
* use var $cacheAction = true; or in the controller method $this->cacheAction = true;
|
||||
*/
|
||||
define('CACHE_CHECK', false);
|
||||
/**
|
||||
* Error constant. Used for differentiating error logging and debugging.
|
||||
* Currently PHP supports LOG_DEBUG
|
||||
*/
|
||||
define('LOG_ERROR', 2);
|
||||
/**
|
||||
* CakePHP includes 3 types of session saves
|
||||
* database or file. Set this to your preferred method.
|
||||
* If you want to use your own save handler place it in
|
||||
* app/config/name.php DO NOT USE file or database as the name.
|
||||
* and use just the name portion below.
|
||||
*
|
||||
* Setting this to cake will save files to /cakedistro/tmp directory
|
||||
* Setting it to php will use the php default save path
|
||||
* Setting it to database will use the database
|
||||
*
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_SAVE', 'database');
|
||||
/**
|
||||
* If using you own table name for storing sessions
|
||||
* set the table name here.
|
||||
* DO NOT INCLUDE PREFIX IF YOU HAVE SET ONE IN database.php
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_TABLE', 'sessions');
|
||||
/**
|
||||
* Set a random string of used in session.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
|
||||
/**
|
||||
* Set the name of session cookie
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_COOKIE', 'sess');
|
||||
/**
|
||||
* Set level of Cake security.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SECURITY', 'high');
|
||||
/**
|
||||
* Set Cake Session time out.
|
||||
* If CAKE_SECURITY define is set
|
||||
* high: multiplied by 10
|
||||
* medium: is multiplied by 100
|
||||
* low is: multiplied by 300
|
||||
*
|
||||
* Number below is seconds.
|
||||
*/
|
||||
define('CAKE_SESSION_TIMEOUT', '120');
|
||||
/**
|
||||
* Uncomment the define below to use cake built in admin routes.
|
||||
* You can set this value to anything you want.
|
||||
* All methods related to the admin route should be prefixed with the
|
||||
* name you set CAKE_ADMIN to.
|
||||
* For example: admin_index, admin_edit
|
||||
*/
|
||||
// define('CAKE_ADMIN', 'admin');
|
||||
/**
|
||||
* The define below is used to turn cake built webservices
|
||||
* on or off. Default setting is off.
|
||||
*/
|
||||
define('WEBSERVICES', 'off');
|
||||
/**
|
||||
* Compress output CSS (removing comments, whitespace, repeating tags etc.)
|
||||
* This requires a/var/cache directory to be writable by the web server (caching).
|
||||
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use Controller::cssTag().
|
||||
*/
|
||||
define('COMPRESS_CSS', false);
|
||||
/**
|
||||
* If set to true, helpers would output data instead of returning it.
|
||||
*/
|
||||
define('AUTO_OUTPUT', false);
|
||||
/**
|
||||
* If set to false, session would not automatically be started.
|
||||
*/
|
||||
define('AUTO_SESSION', true);
|
||||
/**
|
||||
* Set the max size of file to use md5() .
|
||||
*/
|
||||
define('MAX_MD5SIZE', (5 * 1024) * 1024);
|
||||
/**
|
||||
* To use Access Control Lists with Cake...
|
||||
*/
|
||||
define('ACL_CLASSNAME', 'DB_ACL');
|
||||
define('ACL_FILENAME', 'dbacl' . DS . 'db_acl');
|
||||
?>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class DATABASE_CONFIG {
|
||||
var $default = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => '',
|
||||
'password' => '',
|
||||
'database' => '');
|
||||
}
|
||||
?>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: inflections.php,v 1.3 2006-10-08 03:39:21 reed%reedloden.com Exp $ */
|
||||
/**
|
||||
* Custom Inflected Words.
|
||||
*
|
||||
* This file is used to hold words that are not matched in the normail Inflector::pluralize() and
|
||||
* Inflector::singularize()
|
||||
*
|
||||
* PHP versions 4 and %
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 1.0.0.2312
|
||||
* @version $Revision: 1.3 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-10-08 03:39:21 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice');
|
||||
*/
|
||||
$pluralRules = array();
|
||||
/**
|
||||
* This is a key only array of plural words that should not be inflected.
|
||||
* Notice the last comma
|
||||
*
|
||||
* $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox');
|
||||
*/
|
||||
$uninflectedPlural = array();
|
||||
/**
|
||||
* This is a key => value array of plural irregular words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers')
|
||||
*/
|
||||
$irregularPlural = array();
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i')
|
||||
*/
|
||||
$singularRules = array();
|
||||
/**
|
||||
* This is a key only array of singular words that should not be inflected.
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
* as the $uninflectedPlural above.
|
||||
*/
|
||||
$uninflectedSingular = $uninflectedPlural;
|
||||
/**
|
||||
* This is a key => value array of singular irregular words.
|
||||
* Most of the time this will be a reverse of the above $irregularPlural array
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
*
|
||||
* $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother')
|
||||
*/
|
||||
$irregularSingular = array_flip($irregularPlural);
|
||||
?>
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: routes.php,v 1.5 2006-10-10 20:18:59 reed%reedloden.com Exp $ */
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* In this file, you set up routes to your controllers and their actions.
|
||||
* Routes are very important mechanism that allows you to freely connect
|
||||
* different urls to chosen controllers and their actions (functions).
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.5 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-10-10 20:18:59 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
||||
* its action called 'display', and we pass a param to select the view file
|
||||
* to use (in this case, /app/views/pages/home.thtml)...
|
||||
*/
|
||||
$Route->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
/**
|
||||
* ...and connect the rest of 'Pages' controller's urls.
|
||||
*/
|
||||
$Route->connect('/pages/edit', array('controller' => 'pages', 'action' => 'edit'));
|
||||
$Route->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
||||
$Route->connect('/privacy-policy', array('controller' => 'pages', 'action' => 'privacy'));
|
||||
?>
|
||||
@@ -1,80 +0,0 @@
|
||||
CREATE TABLE `comments` (
|
||||
`id` int(10) NOT NULL auto_increment,
|
||||
`assoc` int(10) NOT NULL default '0',
|
||||
`owner` int(10) NOT NULL default '0',
|
||||
`time` int(15) NOT NULL default '0',
|
||||
`text` text collate utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
CREATE TABLE `guests` (
|
||||
`id` int(10) NOT NULL auto_increment,
|
||||
`pid` int(10) NOT NULL default '0',
|
||||
`uid` int(10) NOT NULL default '0',
|
||||
`invited` tinyint(1) NOT NULL default '1',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `pid` (`pid`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
CREATE TABLE `pages` (
|
||||
`id` int(10) NOT NULL auto_increment,
|
||||
`text` text collate utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
INSERT INTO `pages` (`id`, `text`) VALUES (1, '<h2>Join the Fun!</h2>\n<p>All over the world, we're celebrating the launch of Firefox 2. Join the fun by hosting or attending a party. We're targeting the weekend of October 27th for the shared celebration, but if you're hosting, you make the call.</p>\n\n<p>To join the fun, <a href="/users/register">register</a> for a Firefox Party account, and sign up to host or attend.</p>\n\n<p style="border: 1px solid #555; background: #faffd4; padding: 5px; font-weight: bold">Be one of the first 50 party hosts registered and get three extra launch exclusive t-shirts with your purchase of the <a href="">Firefox 2 Party Pack</a>. We're selling the party packs and shirts at cost, so it's a great deal, and for parties with unusually large attendance, we'll be sending out additional swag for door prizes and other give-aways. Stay tuned for updates!</p>');
|
||||
INSERT INTO `pages` (`id`, `text`) VALUES (2, '1162007940');
|
||||
|
||||
CREATE TABLE `parties` (
|
||||
`id` int(10) NOT NULL auto_increment,
|
||||
`owner` int(10) NOT NULL default '0',
|
||||
`name` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`vname` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`address` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`tz` int(2) NOT NULL default '0',
|
||||
`website` text collate utf8_unicode_ci NOT NULL,
|
||||
`notes` text collate utf8_unicode_ci NOT NULL,
|
||||
`date` int(10) NOT NULL default '0',
|
||||
`duration` tinyint(2) NOT NULL default '2',
|
||||
`confirmed` tinyint(1) NOT NULL default '1',
|
||||
`canceled` tinyint(1) NOT NULL default '0',
|
||||
`guestcomments` tinyint(1) NOT NULL default '0',
|
||||
`inviteonly` tinyint(1) NOT NULL default '0',
|
||||
`invitecode` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`lat` float NOT NULL default '0',
|
||||
`long` float NOT NULL default '0',
|
||||
`zoom` tinyint(2) NOT NULL default '1',
|
||||
`useflickr` tinyint(1) NOT NULL default '0',
|
||||
`flickrperms` tinyint(1) NOT NULL default '0',
|
||||
`flickrid` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`flickrusr` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
CREATE TABLE `sessions` (
|
||||
`id` varchar(255) character set latin1 NOT NULL default '',
|
||||
`data` text character set latin1,
|
||||
`expires` int(11) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`id` int(10) NOT NULL auto_increment,
|
||||
`role` tinyint(1) NOT NULL default '0',
|
||||
`email` varchar(255) collate utf8_unicode_ci NOT NULL,
|
||||
`active` varchar(10) collate utf8_unicode_ci NOT NULL default '0',
|
||||
`password` varchar(75) collate utf8_unicode_ci NOT NULL default '',
|
||||
`salt` varchar(9) collate utf8_unicode_ci NOT NULL default '',
|
||||
`name` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`location` tinytext collate utf8_unicode_ci NOT NULL,
|
||||
`tz` tinyint(2) NOT NULL default '0',
|
||||
`website` text collate utf8_unicode_ci NOT NULL,
|
||||
`lat` float NOT NULL default '0',
|
||||
`long` float NOT NULL default '0',
|
||||
`zoom` tinyint(2) NOT NULL default '1',
|
||||
`showemail` tinyint(1) NOT NULL default '0',
|
||||
`showloc` tinyint(1) NOT NULL default '1',
|
||||
`showmap` tinyint(1) NOT NULL default '1',
|
||||
UNIQUE KEY `email` (`email`),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
uses('sanitize');
|
||||
class AdminController extends AppController {
|
||||
var $name = 'Admin';
|
||||
var $uses = array('Party', 'User', 'Comment');
|
||||
var $components = array('Unicode');
|
||||
|
||||
function beforeFilter() {
|
||||
if (empty($_SESSION['User']) || $_SESSION['User']['role'] != 1) {
|
||||
$this->redirect('/');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function index() {
|
||||
$this->set('parties', $this->Party->findAll(null, null, "id ASC"));
|
||||
}
|
||||
|
||||
function users() {
|
||||
$this->set('users', $this->User->findAll(null, null, "id ASC"));
|
||||
}
|
||||
|
||||
function comments() {
|
||||
$this->set('comments', $this->Comment->findAll(null, null, "id ASC"));
|
||||
}
|
||||
|
||||
function edit($type, $id) {
|
||||
if (empty($this->data)) {
|
||||
switch($type) {
|
||||
case 'user':
|
||||
$this->User->id = $id;
|
||||
$user = $this->User->read();
|
||||
$this->set('user', $user);
|
||||
$this->data = $user;
|
||||
break;
|
||||
|
||||
case 'party':
|
||||
$this->Party->id = $id;
|
||||
$party = $this->Party->read();
|
||||
$this->set('party', $party);
|
||||
$this->data = $party;
|
||||
$this->data['Party']['name'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['name']));
|
||||
$this->data['Party']['vname'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['vname']));
|
||||
$this->data['Party']['website'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['website']));
|
||||
$this->data['Party']['address'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['address']));
|
||||
$this->data['Party']['notes'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['notes']));
|
||||
$this->data['Party']['flickrusr'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['flickrusr']));
|
||||
break;
|
||||
|
||||
case 'comment':
|
||||
$this->Comment->id = $id;
|
||||
$comment = $this->Comment->read();
|
||||
$this->set('comment', $comment);
|
||||
|
||||
$uid = $this->User->findById($comment['Comment']['owner']);
|
||||
$this->set('owner', $uid['User']['name']);
|
||||
|
||||
$this->data = $comment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
switch($type) {
|
||||
case 'user':
|
||||
$this->User->id = $id;
|
||||
$this->User->save($this->data);
|
||||
break;
|
||||
|
||||
case 'party':
|
||||
$this->Party->id = $id;
|
||||
$clean = new Sanitize();
|
||||
$clean->cleanArray($this->data);
|
||||
$this->Party->save($this->data);
|
||||
break;
|
||||
|
||||
case 'comment':
|
||||
$this->Comment->id = $id;
|
||||
$this->Comment->save($this->data);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type != 'party')
|
||||
$this->redirect('/admin/'.$type.'s');
|
||||
|
||||
else
|
||||
$this->redirect('/admin/');
|
||||
}
|
||||
}
|
||||
|
||||
function delete($type, $id) {
|
||||
switch($type) {
|
||||
case 'user':
|
||||
$this->User->del($id);
|
||||
$this->User->query("DELETE FROM guests WHERE uid = $id");
|
||||
break;
|
||||
|
||||
case 'party':
|
||||
$this->Party->del($id);
|
||||
$this->Party->query("DELETE FROM guests WHERE pid = $id");
|
||||
$this->Party->query("DELETE FROM comments WHERE assoc = $id");
|
||||
break;
|
||||
|
||||
case 'comment':
|
||||
$this->Comment->del($id);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type != 'party')
|
||||
$this->redirect('/admin/'.$type.'s');
|
||||
|
||||
else
|
||||
$this->redirect('/admin/');
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
uses('sanitize');
|
||||
|
||||
class CommentsController extends AppController {
|
||||
var $name = 'Comments';
|
||||
var $components = array('Security');
|
||||
|
||||
function beforeFilter() {
|
||||
$this->Security->requirePost('add');
|
||||
}
|
||||
|
||||
function add($pid, $uid) {
|
||||
if (!$this->Session->check('User') || $uid != $_SESSION['User']['id'])
|
||||
$this->redirect('/');
|
||||
|
||||
if (!empty($this->data) && $this->Comment->canComment($pid, $uid)) {
|
||||
// Explictly destroy the last model to avoid an edit instead of an insert
|
||||
$this->Comment->create();
|
||||
|
||||
$clean = new Sanitize();
|
||||
$text = $clean->html($this->data['Comment']['text']);
|
||||
$this->data['Comment']['text'] = nl2br($text);
|
||||
$this->data['Comment']['owner'] = $uid;
|
||||
$this->data['Comment']['assoc'] = $pid;
|
||||
$this->data['Comment']['time'] = mktime();
|
||||
|
||||
if ($this->Comment->save($this->data)) {
|
||||
$this->redirect('/parties/view/'.$pid.'#c'.$this->Comment->getLastInsertID());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
$this->redirect('/parties/view/'.$pid);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class HashComponent extends Object {
|
||||
|
||||
function password($pass, $data) {
|
||||
$string = $pass.uniqid(rand(), true).$data;
|
||||
$salt = substr(md5($string), 0, 9);
|
||||
$p = sha1($pass.$salt);
|
||||
$rv = array('pass' => $p, 'salt' => $salt);
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function keygen($chars) {
|
||||
$key = null;
|
||||
$pool = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
for ($i = 0; $i < $chars; $i++)
|
||||
$key .= $pool{rand(0,61)};
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
class MailComponent extends Object {
|
||||
var $from;
|
||||
var $to;
|
||||
var $reply;
|
||||
var $subject;
|
||||
var $message;
|
||||
var $envelope;
|
||||
var $head = "<strong>Firefox Party!</strong><br/>";
|
||||
var $foot;
|
||||
|
||||
|
||||
function mail($params) {
|
||||
if (array_key_exists('from', $params))
|
||||
$this->from = $params['from'];
|
||||
|
||||
if (array_key_exists('to', $params))
|
||||
$this->to = $params['to'];
|
||||
|
||||
if (array_key_exists('reply', $params))
|
||||
$this->reply = $params['reply'];
|
||||
|
||||
if (array_key_exists('subject', $params))
|
||||
$this->subject = $params['subject'];
|
||||
|
||||
if (array_key_exists('message', $params))
|
||||
$this->message = $params['message'];
|
||||
|
||||
if (array_key_exists('envelope', $params))
|
||||
$this->envelope = $params['envelope'];
|
||||
|
||||
if (array_key_exists('type', $params)) {
|
||||
switch($params['type']) {
|
||||
case 'act':
|
||||
$this->message = $this->head."<br/>\nThank you for registering! To activate your account, <a href=\"".$params['link']."\">click here</a> or paste the link below into your browser:<br/> ".$params['link'].$this->foot;
|
||||
break;
|
||||
|
||||
case 'prec':
|
||||
$this->message = $this->head."<br/>\nTo reset your password, <a href=\"".$params['link']."\">click here</a> or paste the link below into your browser:<br/> ".$params['link'].$this->foot;
|
||||
break;
|
||||
|
||||
case 'invite':
|
||||
$this->message = $this->head."<br/>\nYou've been invited by a friend to join them in celebrating the release of Firefox 2. Simply <a href=\"".$params['link']."\">click here</a> to confirm or cancel this invitation. If you don't already have an account, you'll need to create one.\n
|
||||
If you're unable to use the link above, simply paste the following URL into your browser: ".$params['link'].$this->foot;
|
||||
break;
|
||||
|
||||
case 'cancel':
|
||||
$this->message = $this->head."<br/>\nThe party you were attending has been canceled. For more information, please <a href=\"".$params['link']."\">click here</a>, or see the link below.\n ".$params['link'].$this->foot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function make_headers($type='html') {
|
||||
$headers = '';
|
||||
|
||||
switch($type) {
|
||||
case 'html':
|
||||
$headers .= 'MIME-Version: 1.0' . "\r\n";
|
||||
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($this->from)) {
|
||||
$headers .= "From: {$this->from}\r\n";
|
||||
|
||||
if (!empty($this->reply))
|
||||
$headers .= "Reply-To: {$this->reply}\r\n";
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
function make_additional_parameters() {
|
||||
if (!empty($this->envelope)) {
|
||||
return '-f'.$this->envelope;
|
||||
}
|
||||
}
|
||||
|
||||
function send() {
|
||||
mail($this->to, $this->subject, $this->message, $this->make_headers(), $this->make_additional_parameters());
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class UnicodeComponent extends Object {
|
||||
/**
|
||||
* Unicode utilities. Converts and encodes characters up to 0xFFFF (65535)
|
||||
*/
|
||||
function unicode2utf($char) {
|
||||
if ($char < 128) {
|
||||
$rv = chr($char);
|
||||
}
|
||||
|
||||
else if ($char < 2048) {
|
||||
$rv = chr(192 + (($char - ($char % 64)) / 64));
|
||||
$rv .= chr(128 + ($char % 64));
|
||||
}
|
||||
|
||||
else {
|
||||
$rv = chr(224 + (($char - ($char % 4096)) / 4096));
|
||||
$rv .= chr(128 + ((($char % 4096) - ($char % 64)) / 64));
|
||||
$rv .= chr(128 + ($char % 64));
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function utf2unicode($char) {
|
||||
if (ord($char{0}) < 128)
|
||||
$rv = ord($char);
|
||||
|
||||
else if (ord($char{0}) < 224)
|
||||
$rv = ((ord($char{0}) - 192) * 64) + (ord($char{1}) - 128);
|
||||
|
||||
else if (ord($char{0}) < 240)
|
||||
$rv = ((ord($char{0}) - 224) * 4096) + ((ord($char{1}) - 128) * 64 + (ord($char{2}) - 128));
|
||||
|
||||
else
|
||||
$rv = ((ord($char{0}) - 240) * 262144) + ((ord($char{1}) - 128) * 4096) + ((ord($char{2}) - 128) * 64) + (ord($char{3}) - 128);
|
||||
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
vendor('webServices');
|
||||
class FeedsController extends AppController {
|
||||
var $name = 'Feeds';
|
||||
var $components = array('Unicode');
|
||||
|
||||
function index() {
|
||||
header('Content-type: application/rss+xml');
|
||||
$this->layout = 'ajax';
|
||||
$this->set('count', $this->Feed->findCount());
|
||||
}
|
||||
|
||||
function latest() {
|
||||
header('Content-type: application/rss+xml');
|
||||
$this->layout = 'ajax';
|
||||
$this->set('latest', $this->Feed->findAll('', '', 'id DESC', 10, 1));
|
||||
}
|
||||
|
||||
function users() {
|
||||
header('Content-type: application/rss+xml');
|
||||
$this->layout = 'ajax';
|
||||
$this->set('count', $this->Feed->getUserCount());
|
||||
}
|
||||
|
||||
function comments($id = null) {
|
||||
$this->layout = 'ajax';
|
||||
header('Content-type: application/rss+xml');
|
||||
if (!is_numeric($id))
|
||||
return;
|
||||
|
||||
$this->set('comments', $this->Feed->getComments($id));
|
||||
$this->set('pid', $id);
|
||||
}
|
||||
|
||||
function photos($id = null) {
|
||||
$this->layout = 'ajax';
|
||||
header('Content-type: application/atom+xml');
|
||||
if (!is_numeric($id))
|
||||
return;
|
||||
|
||||
$party = $this->Feed->findById($id);
|
||||
$this->set('party', $party);
|
||||
|
||||
if (FLICKR_API_KEY != null && !$party['Feeds']['canceled']) {
|
||||
if ($party['Feeds']['useflickr'] == 1) {
|
||||
$data = array('type' => 'flickr', 'userid' => $party['Feeds']['flickrid'], 'randomize' => false);
|
||||
$flickr = new webServices($data);
|
||||
$photoset = $flickr->fetchPhotos(FLICKR_TAG_PREFIX.$id, 30, !$party['Feeds']['flickrperms']);
|
||||
$this->set('flickr', $photoset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upcoming($limit = null) {
|
||||
$this->layout = 'ajax';
|
||||
header('Content-type: application/rss+xml');
|
||||
|
||||
($limit == null) ? $limit = 25 : $limit = intval($limit);
|
||||
|
||||
$this->set('latest', $this->Feed->findAll('WHERE date > '. time(), '', 'date ASC', $limit, 1));
|
||||
}
|
||||
|
||||
function ical() {
|
||||
$this->layout = 'ajax';
|
||||
header('Content-type: text/calendar');
|
||||
header("Content-Disposition: inline; filename=partylist.ics");
|
||||
$back = time() - 172800;
|
||||
$events = $this->Feed->findAll('WHERE date > '. $back, '', 'date ASC', null, 1);
|
||||
|
||||
$cal = array();
|
||||
|
||||
foreach($events as $event) {
|
||||
$event['Feeds']['name'] =
|
||||
preg_replace(array("/&#(\d{2,5});/e", "/(\n|\r|\f)/", "/\,/"),
|
||||
array('$this->Unicode->unicode2utf(${1})', ' ', '\,'),
|
||||
html_entity_decode($event['Feeds']['name']));
|
||||
$event['Feeds']['address'] =
|
||||
preg_replace(array("/&#(\d{2,5});/e", "/(\n|\r|\f)/", "/\,/"),
|
||||
array('$this->Unicode->unicode2utf(${1})', ' ', '\,'),
|
||||
html_entity_decode($event['Feeds']['address']));
|
||||
$event['Feeds']['notes'] =
|
||||
preg_replace(array("/&#(\d{2,5});/e", "/(\n|\r|\f)/", "/\,/"),
|
||||
array('$this->Unicode->unicode2utf(${1})', ' ', '\,'),
|
||||
html_entity_decode($event['Feeds']['notes']));
|
||||
array_push($cal, $event);
|
||||
}
|
||||
$this->set('events', $cal);
|
||||
}
|
||||
|
||||
function topguests($limit = null) {
|
||||
$this->layout = 'ajax';
|
||||
header('Content-type: application/rss+xml');
|
||||
|
||||
($limit == null) ? $limit = 25 : $limit = intval($limit);
|
||||
|
||||
$rv = $this->Feed->query("SELECT parties.name AS name,
|
||||
guests.pid AS id,
|
||||
COUNT(guests.pid) AS count
|
||||
FROM guests
|
||||
LEFT JOIN parties
|
||||
ON guests.pid = parties.id
|
||||
GROUP BY guests.pid
|
||||
ORDER BY count DESC
|
||||
LIMIT $limit");
|
||||
$this->set('items', $rv);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
uses('sanitize');
|
||||
class PagesController extends AppController {
|
||||
var $name = 'Pages';
|
||||
var $components = array('Unicode');
|
||||
|
||||
function display() {
|
||||
$this->pageTitle = 'Home';
|
||||
$this->set('current', 'home');
|
||||
$this->set('pcount', $this->Page->findCount());
|
||||
$this->set('ucount', $this->Page->getUsers());
|
||||
$text = $this->Page->query('SELECT text FROM pages WHERE id = 1');
|
||||
$time = $this->Page->query('SELECT text FROM pages WHERE id = 2');
|
||||
$this->set('time', $time[0]['pages']['text']);
|
||||
$this->set('front_text', preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($text[0]['pages']['text'])));
|
||||
}
|
||||
|
||||
function privacy() {
|
||||
$this->pageTitle = 'Privacy Policy';
|
||||
}
|
||||
|
||||
function edit() {
|
||||
if (isset($_SESSION['User']['id']) && $_SESSION['User']['role'] == 1) {
|
||||
if (empty($this->data)) {
|
||||
$text = $this->Page->query('SELECT text FROM pages WHERE id = 1');
|
||||
$time = $this->Page->query('SELECT text FROM pages WHERE id = 2');
|
||||
$this->data['Pages']['text'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($text[0]['pages']['text']));
|
||||
$this->set('selected', date('Y-m-d H:i:s', $time[0]['pages']['text']));
|
||||
}
|
||||
|
||||
else {
|
||||
// Paranoid? Nah...
|
||||
if ($_SESSION['User']['role'] == 1) {
|
||||
$clean = new Sanitize();
|
||||
$clean->cleanArray($this->data);
|
||||
$date = mktime($this->data['Pages']['date_hour'],
|
||||
$this->data['Pages']['date_min'],
|
||||
0,
|
||||
$this->data['Pages']['date_month'],
|
||||
$this->data['Pages']['date_day'],
|
||||
$this->data['Pages']['date_year']);
|
||||
|
||||
$this->Page->execute('UPDATE pages SET text = "'.$this->data['Pages']['text'].'" WHERE pages.id = 1');
|
||||
$this->Page->execute('UPDATE pages SET text = "'.$date.'" WHERE pages.id = 2');
|
||||
$this->redirect('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
die();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,472 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
uses('sanitize');
|
||||
vendor('webServices');
|
||||
class PartiesController extends AppController {
|
||||
var $name = 'Parties';
|
||||
var $uses = array('Party', 'Comment');
|
||||
var $helpers = array('Html', 'Form');
|
||||
var $components = array('Hash', 'Mail', 'Unicode');
|
||||
|
||||
function index() {
|
||||
$this->pageTitle = 'Party Map';
|
||||
$this->set('current', 'map');
|
||||
|
||||
if (!empty($this->data)) {
|
||||
$gcoder = new webServices(array('type' => 'geocode'));
|
||||
$loc = $gcoder->geocode($this->data['Party']['mloc']);
|
||||
|
||||
if ($loc)
|
||||
$this->set('map', 'initMashUp('.$loc['lat'].', '.$loc['lng'].');');
|
||||
|
||||
else
|
||||
$this->set('map', 'initMashUp();');
|
||||
}
|
||||
|
||||
else
|
||||
$this->set('map', 'initMashUp();');
|
||||
}
|
||||
|
||||
function add() {
|
||||
if (!$this->Session->check('User'))
|
||||
$this->redirect('/users/login');
|
||||
|
||||
$this->pageTitle = 'Create Party';
|
||||
$this->set('current', 'create');
|
||||
$this->set('map', 'mapInit()');
|
||||
|
||||
if(empty($this->data)) {
|
||||
$this->set('utz', $_SESSION['User']['tz']);
|
||||
$this->render();
|
||||
}
|
||||
|
||||
else {
|
||||
$temp = array('lat' => $this->data['Party']['lat'],
|
||||
'long' => $this->data['Party']['long'],
|
||||
'tz' => $this->data['Party']['tz']);
|
||||
|
||||
$clean = new Sanitize();
|
||||
$clean->cleanArray($this->data);
|
||||
|
||||
$this->data['Party']['lat'] = floatval($temp['lat']);
|
||||
$this->data['Party']['long'] = floatval($temp['long']);
|
||||
$this->data['Party']['tz'] = intval($temp['tz']);
|
||||
$this->set('utz', $this->data['Party']['tz']);
|
||||
|
||||
// Convert the selected time to GMT
|
||||
$secoffset = ($this->data['Party']['tz'] * 60 * 60);
|
||||
$offsetdate = gmmktime($this->data['Party']['hour_hour'],
|
||||
$this->data['Party']['minute_min'],
|
||||
0,
|
||||
$this->data['Party']['month_hour'],
|
||||
$this->data['Party']['day_day'],
|
||||
$this->data['Party']['year_year']);
|
||||
$this->data['Party']['date'] = ($offsetdate + $secoffset);
|
||||
$this->data['Party']['duration'] = intval($this->data['Party']['duration']);
|
||||
|
||||
$this->data['Party']['invitecode'] = $this->Hash->keygen(10);
|
||||
$this->data['Party']['owner'] = $_SESSION['User']['id'];
|
||||
|
||||
if (!preg_match("/^(http|https)\:\/\//i", $this->data['Party']['website']) &&
|
||||
!empty($this->data['Party']['website']))
|
||||
$this->Party->invalidate('website');
|
||||
|
||||
if ($this->Party->validates($this->data)) {
|
||||
if($this->Party->save($this->data)) {
|
||||
$this->Session->setFlash('Your party has been created!', 'infoFlash');
|
||||
$this->redirect('/parties/view/'.$this->Party->getLastInsertId());
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Session->setFlash('Please correct the errors below.', 'errorFlash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function edit($id) {
|
||||
$this->Party->id = $id;
|
||||
$party = $this->Party->read();
|
||||
$this->set('party', $party);
|
||||
$this->pageTitle = 'Edit Party';
|
||||
$this->set('current', 'create');
|
||||
|
||||
if (empty($_SESSION['User']['id']))
|
||||
$this->redirect('/users/login/');
|
||||
|
||||
if ($party['Party']['owner'] != $_SESSION['User']['id'])
|
||||
$this->redirect('/parties/view/'.$id);
|
||||
|
||||
else {
|
||||
if (empty($this->data)) {
|
||||
$this->data = $party;
|
||||
|
||||
$date = array('hour' => intval(date('h', $party['Party']['date'])),
|
||||
'min' => intval(date('i', $party['Party']['date'])),
|
||||
'mon' => intval(date('m', $party['Party']['date'])),
|
||||
'day' => intval(date('d', $party['Party']['date'])),
|
||||
'year' => intval(date('Y', $party['Party']['date'])),
|
||||
'tz' => $party['Party']['tz']);
|
||||
|
||||
$this->set('date', $date);
|
||||
$this->data['Party']['name'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['name']));
|
||||
$this->data['Party']['vname'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['vname']));
|
||||
$this->data['Party']['website'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['website']));
|
||||
$this->data['Party']['address'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['address']));
|
||||
$this->data['Party']['notes'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['notes']));
|
||||
$this->data['Party']['flickrusr'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['Party']['flickrusr']));
|
||||
|
||||
if (GMAP_API_KEY != null) {
|
||||
if ($this->data['Party']['lat'])
|
||||
$this->set('map', 'mapInit('.$this->data['Party']['lat'].','.$this->data['Party']['long'].','.$this->data['Party']['zoom'].')');
|
||||
else
|
||||
$this->set('map', 'mapInit()');
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$clean = new Sanitize();
|
||||
$temp = array('lat' => $clean->sql($this->data['Party']['lat']),
|
||||
'long' => $clean->sql($this->data['Party']['long']),
|
||||
'tz' => $clean->sql($this->data['Party']['tz']));
|
||||
|
||||
$clean->cleanArray($this->data);
|
||||
|
||||
$this->data['Party']['lat'] = floatval($temp['lat']);
|
||||
$this->data['Party']['long'] = floatval($temp['long']);
|
||||
$this->data['Party']['tz'] = intval($temp['tz']);
|
||||
|
||||
$secoffset = ($this->data['Party']['tz'] * 60 * 60);
|
||||
|
||||
$offsetdate = gmmktime($this->data['Party']['hour_hour'],
|
||||
$this->data['Party']['minute_min'],
|
||||
0,
|
||||
$this->data['Party']['month_hour'],
|
||||
$this->data['Party']['day_day'],
|
||||
$this->data['Party']['year_year']);
|
||||
|
||||
$this->data['Party']['date'] = ($offsetdate - $secoffset);
|
||||
$this->data['Party']['owner'] = $party['Party']['owner'];
|
||||
$this->data['Party']['duration'] = intval($this->data['Party']['duration']);
|
||||
|
||||
$date = array('hour' => intval(date('h', $party['Party']['date'])),
|
||||
'min' => intval(date('i', $party['Party']['date'])),
|
||||
'mon' => intval(date('m', $party['Party']['date'])),
|
||||
'day' => intval(date('d', $party['Party']['date'])),
|
||||
'year' => intval(date('Y', $party['Party']['date'])),
|
||||
'tz' => $party['Party']['tz']);
|
||||
$this->set('date', $date);
|
||||
|
||||
if (!preg_match("/^(http|https)\:\/\//i", $this->data['Party']['website']) &&
|
||||
!empty($this->data['Party']['website']))
|
||||
$this->Party->invalidate('website');
|
||||
|
||||
if ($this->data['Party']['flickrusr'] != $party['Party']['flickrusr']) {
|
||||
$params = array('type' => 'flickr', 'username' => $this->data['Party']['flickrusr']);
|
||||
$flick = new webServices($params);
|
||||
$this->data['Party']['flickrid'] = $flick->getFlickrId();
|
||||
}
|
||||
|
||||
if ($this->Party->validates($this->data)) {
|
||||
if ($this->Party->save($this->data)) {
|
||||
$this->Session->setFlash('Party edited successfully.', 'infoFlash');
|
||||
$this->redirect('parties/view/'.$id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function view($id = null, $page = null) {
|
||||
if ($id == 'all') {
|
||||
$this->pageTitle = 'All Parties';
|
||||
$this->set('current', 'parties');
|
||||
|
||||
//Paginate!
|
||||
$count = $this->Party->findCount();
|
||||
$pages = ceil($count/100);
|
||||
if ($page == null)
|
||||
$page = 1;
|
||||
if ($page > 1)
|
||||
$this->set('prev', $page - 1);
|
||||
if ($page < $pages)
|
||||
$this->set('next', $page + 1);
|
||||
|
||||
$deck = $this->Party->findAll(null, null, "id ASC", 100, $page);
|
||||
shuffle($deck);
|
||||
$this->set('parties', $deck);
|
||||
}
|
||||
|
||||
else if (is_numeric($id)) {
|
||||
$party = $this->Party->findById($id);
|
||||
if (empty($party['Party']['id']))
|
||||
$this->redirect('/parties/view/all');
|
||||
|
||||
$this->set('current', 'parties');
|
||||
$this->set('host', $this->Party->getHost($party['Party']['owner']));
|
||||
$this->set('party', $party);
|
||||
$this->set('isguest', $this->Party->isGuest($id, @$_SESSION['User']['id']));
|
||||
$this->pageTitle = $party['Party']['name'];
|
||||
$this->set('map', 'mapInit('.$party['Party']['lat'].','.$party['Party']['long'].
|
||||
','.$party['Party']['zoom'].',\'stationary\')');
|
||||
$this->set('guests', $this->Party->getGuests($party['Party']['id']));
|
||||
$this->set('comments', $this->Party->getComments($id));
|
||||
|
||||
if (FLICKR_API_KEY != null) {
|
||||
if ($party['Party']['useflickr'] == 1) {
|
||||
$data = array('type' => 'flickr', 'userid' => $party['Party']['flickrid'], 'randomize' => true);
|
||||
$flickr = new webServices($data);
|
||||
$photoset = $flickr->fetchPhotos(FLICKR_TAG_PREFIX.$party['Party']['id'], 15, (($party['Party']['flickrperms']) ? false : true));
|
||||
$this->set('flickr', array_slice($photoset, 0, 9));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
$this->redirect('/parties/view/all');
|
||||
}
|
||||
|
||||
function invite($id = null) {
|
||||
$this->pageTitle = "Invite a Guest";
|
||||
if (is_numeric($id)) {
|
||||
$party = $this->Party->findById($id);
|
||||
if (empty($party['Party']['id']) ||
|
||||
$party['Party']['owner'] != $_SESSION['User']['id'] ||
|
||||
$party['Party']['canceled'] == 1)
|
||||
$this->redirect('/parties/view/all');
|
||||
|
||||
else {
|
||||
$this->set('partyid', $party['Party']['id']);
|
||||
$this->set('inviteurl', APP_BASE.'/parties/invited/'.$party['Party']['invitecode']);
|
||||
|
||||
$clean = new Sanitize();
|
||||
$uid = $clean->sql($_SESSION['User']['id']);
|
||||
$email = $this->Party->query("SELECT email FROM users WHERE id = ".$uid);
|
||||
|
||||
if (!empty($this->data)) {
|
||||
if ($this->Party->validates($this->data)) {
|
||||
$message = array('from' => APP_NAME.' <'.APP_EMAIL.'>',
|
||||
'envelope' => APP_EMAIL,
|
||||
'to' => $this->data['Party']['einvite'],
|
||||
'reply' => $email[0]['users']['email'],
|
||||
'subject' => 'You\'ve been invited to '.APP_NAME.'!',
|
||||
'link' => APP_BASE.'/parties/invited/'.$party['Party']['invitecode'],
|
||||
'type' => 'invite');
|
||||
|
||||
$this->Mail->mail($message);
|
||||
$this->Mail->send();
|
||||
|
||||
$this->Session->setFlash($this->data['Party']['einvite'].' has been
|
||||
invited. You can invite another guest below or <a href="'.APP_BASE.'/parties/view/'.$id.'/">click here</a>
|
||||
to return to your party.', 'infoFlash');
|
||||
$this->data['Party']['einvite'] = null;
|
||||
}
|
||||
else {
|
||||
$this->validateErrors($this->Party);
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function invited($icode = null, $conf = null) {
|
||||
$this->pageTitle = "Confirm Invite";
|
||||
if ($icode == 'cancel') {
|
||||
$this->Session->delete('invite');
|
||||
$this->Session->delete('invitestep');
|
||||
$this->redirect('/');
|
||||
}
|
||||
|
||||
else {
|
||||
$clean = new Sanitize();
|
||||
$icode = $clean->sql($icode);
|
||||
$party = $this->Party->findByInvitecode($icode);
|
||||
|
||||
if (empty($party['Party']['id'])) {
|
||||
$this->Session->setFlash('Could not find a party matching that invite code, please check it and try again.', 'errorFlash');
|
||||
}
|
||||
|
||||
else {
|
||||
if (!empty($_SESSION['User']['id']) && !empty($_SESSION['invitestep']) && $conf == 'confirm') {
|
||||
$this->Party->addGuest($_SESSION['User']['id'], $_SESSION['invite']);
|
||||
$this->Session->setFlash('You have been successfully added to this party.', 'infoFlash');
|
||||
$this->redirect('/parties/view/'.$party['Party']['id']);
|
||||
}
|
||||
|
||||
else if (!empty($_SESSION['User']['id'])) {
|
||||
$this->set('confirm_only', true);
|
||||
$this->set('party', $party);
|
||||
$this->set('icode', $icode);
|
||||
$this->Session->write('invitestep', 'true');
|
||||
$this->Session->write('invite', $icode);
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Session->write('invite', $icode);
|
||||
$this->set('party', $party);
|
||||
$this->set('icode', $icode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rsvp($pid) {
|
||||
if (is_numeric($pid) && isset($_SESSION['User']['id'])) {
|
||||
$party = $this->Party->findById($pid);
|
||||
if (empty($party['Party']['id'])) {
|
||||
$this->Session->setFlash('Invalid party id.', 'errorFlash');
|
||||
$this->redirect('/parties/view/all');
|
||||
}
|
||||
|
||||
else {
|
||||
if ($party['Party']['inviteonly']) {
|
||||
$this->Session->setFlash('This party invite only, you\'ll need an
|
||||
invitation from the host to join in', 'errorFlash');
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Party->rsvp($pid, $_SESSION['User']['id']);
|
||||
$this->Session->setFlash('You have been successfully added to this party.', 'infoFlash');
|
||||
$this->redirect('/parties/view/'.$pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
$this->redirect('/parties/view/all');
|
||||
}
|
||||
|
||||
function unrsvp($pid) {
|
||||
if (is_numeric($pid) && isset($_SESSION['User']['id'])) {
|
||||
$party = $this->Party->findById($pid);
|
||||
if (empty($party['Party']['id'])) {
|
||||
$this->Session->setFlash('Invalid party id.', 'errorFlash');
|
||||
$this->redirect('/parties/view/all');
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Party->unrsvp($pid, $_SESSION['User']['id']);
|
||||
$this->Session->setFlash('You have been successfully removed from this party.', 'infoFlash');
|
||||
$this->redirect('/parties/view/'.$pid);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
$this->redirect('/parties/view/all');
|
||||
}
|
||||
|
||||
function cancel($pid) {
|
||||
$this->pageTitle = "Cancel Party";
|
||||
if (!is_numeric($pid) || !isset($_SESSION['User']['id']))
|
||||
$this->redirect('/');
|
||||
|
||||
else
|
||||
$this->set('pid', $pid);
|
||||
|
||||
$party = $this->Party->findById($pid);
|
||||
if ($_SESSION['User']['id'] != $party['Party']['owner'])
|
||||
die();
|
||||
|
||||
if (!empty($this->data) && $_SESSION['User']['id'] == $party['Party']['owner']) {
|
||||
if ($this->data['Party']['confcancel'] == 1) {
|
||||
$guests = $this->Party->getGuests($pid);
|
||||
$guest_count = count($guests);
|
||||
|
||||
foreach($guests as $guest) {
|
||||
$message = array('from' => APP_NAME.' <'.APP_EMAIL.'>',
|
||||
'envelope' => APP_EMAIL,
|
||||
'to' => $guest['users']['email'],
|
||||
'reply' => $_SESSION['User']['email'],
|
||||
'subject' => 'Party Cancellation Notice',
|
||||
'link' => APP_BASE.'/parties/view/'.$pid,
|
||||
'type' => 'cancel');
|
||||
|
||||
$this->Mail->mail($message);
|
||||
$this->Mail->send();
|
||||
}
|
||||
|
||||
$this->Party->query("DELETE FROM guests WHERE pid = $pid LIMIT $guest_count");
|
||||
$this->Party->query("UPDATE parties SET canceled = '1', invitecode = '0' WHERE parties.id = $pid LIMIT 1");
|
||||
|
||||
$this->redirect('/parties/view/'.$pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uncancel($pid) {
|
||||
if (!is_numeric($pid) || !isset($_SESSION['User']['id']))
|
||||
$this->redirect('/');
|
||||
|
||||
$party = $this->Party->findById($pid);
|
||||
if ($_SESSION['User']['id'] != $party['Party']['owner'])
|
||||
die();
|
||||
|
||||
$key = $this->Hash->keygen(10);
|
||||
$this->Party->query("UPDATE parties SET canceled = '0', invitecode = '$key' WHERE parties.id = $pid LIMIT 1");
|
||||
$this->redirect('/parties/view/'.$pid);
|
||||
}
|
||||
|
||||
function js($type = null, $data = null) {
|
||||
$this->layout = 'ajax';
|
||||
|
||||
if ($type == 'html') {
|
||||
header('Content-type: text/plain');
|
||||
$party = $this->Party->findById($data);
|
||||
$this->set('party', $party);
|
||||
}
|
||||
|
||||
else {
|
||||
header('Content-type: text/javascript');
|
||||
$parties = $this->Party->findAll();
|
||||
$this->set('parties', $parties);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,437 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
uses('sanitize');
|
||||
class UsersController extends AppController {
|
||||
var $name = 'Users';
|
||||
var $uses = array('User', 'Party');
|
||||
var $helpers = array('Html', 'Form');
|
||||
var $components = array('Security', 'Hash', 'Mail');
|
||||
|
||||
function index() {
|
||||
if (!isset($_SESSION['User'])) {
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
|
||||
$this->pageTitle = 'My Profile';
|
||||
|
||||
$user = $this->Session->read('User');
|
||||
$this->set('parties', $this->User->memberOf($user['id']));
|
||||
$this->set('hparties', $this->User->hostOf($user['id']));
|
||||
$this->set('iparties', $this->User->invitedTo($user['id']));
|
||||
}
|
||||
|
||||
function register() {
|
||||
$this->pageTitle = 'Register';
|
||||
$this->set('map', 'mapInit()');
|
||||
|
||||
if(empty($this->data)) {
|
||||
$this->set('utz', '0');
|
||||
$this->render();
|
||||
}
|
||||
|
||||
else {
|
||||
if ($this->User->findByEmail($this->data['User']['email']))
|
||||
$this->User->invalidate('email');
|
||||
|
||||
if ($this->data['User']['email'] !== $this->data['User']['confemail'])
|
||||
$this->User->invalidate('confemail');
|
||||
|
||||
if (!preg_match("/^(http|https)\:\/\//i", $this->data['User']['website']) &&
|
||||
!empty($this->data['User']['website']))
|
||||
$this->User->invalidate('website');
|
||||
|
||||
if ($this->data['User']['password'] !== $this->data['User']['confpass'])
|
||||
$this->User->invalidate('confpass');
|
||||
|
||||
if (empty($this->data['User']['password']) || empty($this->data['User']['confpass']))
|
||||
$this->User->invalidate('password');
|
||||
|
||||
// Repopulate the timezone with right value in case there's a validation error
|
||||
$this->set('utz', $this->data['User']['tz']);
|
||||
|
||||
if ($this->User->validates($this->data)) {
|
||||
$clean = new Sanitize();
|
||||
// Generate and set the password, salt and activation key
|
||||
$pass = $this->Hash->password($this->data['User']['password'],
|
||||
$this->data['User']['email']);
|
||||
$this->data['User']['active'] = $this->Hash->keygen(10);
|
||||
$this->data['User']['password'] = $pass['pass'];
|
||||
$this->data['User']['salt'] = $pass['salt'];
|
||||
|
||||
// Save a few fields from the wrath of cleanArray()
|
||||
$temp = array('lat' => $this->data['User']['lat'],
|
||||
'long' => $this->data['User']['long'],
|
||||
'tz' => $this->data['User']['tz'],
|
||||
'email' => $this->data['User']['email']);
|
||||
// Scrub 'a dub
|
||||
$clean->cleanArray($this->data);
|
||||
$this->data['User']['email'] = $temp['email'];
|
||||
$this->data['User']['long'] = floatval($temp['long']);
|
||||
$this->data['User']['lat'] = floatval($temp['lat']);
|
||||
$this->data['User']['tz'] = intval($temp['tz']);
|
||||
$this->data['User']['role'] = 0;
|
||||
|
||||
if($this->User->save($this->data)) {
|
||||
$message = array('from' => APP_NAME.' <'.APP_EMAIL.'>',
|
||||
'envelope' => APP_EMAIL,
|
||||
'to' => $this->data['User']['email'],
|
||||
'subject' => 'Your '.APP_NAME.' Registration',
|
||||
'link' => APP_BASE.'/users/activate/'.$this->data['User']['active'],
|
||||
'type' => 'act');
|
||||
$this->Mail->mail($message);
|
||||
$this->Mail->send();
|
||||
|
||||
if (isset($_SESSION['invite']))
|
||||
$this->Party->addGuest($this->User->getLastInsertId(), $_SESSION['invite']);
|
||||
|
||||
$this->Session->setFlash('Thank you for registering! To login, you\'ll
|
||||
need to activate your account. Please check
|
||||
your email for your activation link.', 'infoFlash');
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
|
||||
else {
|
||||
$this->data['User']['password'] = null;
|
||||
$this->data['User']['confpass'] = null;
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$this->data['User']['password'] = null;
|
||||
$this->data['User']['confpass'] = null;
|
||||
$this->Session->setFlash('There was an error in your submission. Please
|
||||
correct the errors shown below and try again.',
|
||||
'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function edit() {
|
||||
if (!isset($_SESSION['User'])) {
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
$this->set('error', false);
|
||||
$this->pageTitle = 'Edit My Account';
|
||||
if (empty($this->data)) {
|
||||
$this->User->id = $_SESSION['User']['id'];
|
||||
$this->data = $this->User->read();
|
||||
$this->data['User']['password'] = "";
|
||||
$this->set('utz', $this->data['User']['tz']);
|
||||
|
||||
$this->data['User']['name'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['User']['name']));
|
||||
$this->data['User']['website'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['User']['website']));
|
||||
$this->data['User']['location'] = preg_replace("/&#(\d{2,5});/e",
|
||||
'$this->Unicode->unicode2utf(${1})',
|
||||
html_entity_decode($this->data['User']['location']));
|
||||
|
||||
if (GMAP_API_KEY != null) {
|
||||
if ($this->data['User']['lat'])
|
||||
$this->set('map', 'mapInit('.$this->data['User']['lat'].','.$this->data['User']['long'].','.$this->data['User']['zoom'].')');
|
||||
else
|
||||
$this->set('map', 'mapInit()');
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$user = $this->User->findById($_SESSION['User']['id']);
|
||||
$this->User->id = $user['User']['id'];
|
||||
$this->set('utz', $user['User']['tz']);
|
||||
|
||||
$clean = new Sanitize();
|
||||
$temp = array('password' => $this->data['User']['password'],
|
||||
'confpassword' => $this->data['User']['confpassword'],
|
||||
'lat' => $clean->sql($this->data['User']['lat']),
|
||||
'long' => $clean->sql($this->data['User']['long']),
|
||||
'tz' => $clean->sql($this->data['User']['tz']));
|
||||
//Nuke everything else
|
||||
$clean->cleanArray($this->data);
|
||||
|
||||
$this->data['User']['email'] = $user['User']['email'];
|
||||
$this->data['User']['password'] = $temp['password'];
|
||||
$this->data['User']['confpassword'] = $temp['confpassword'];
|
||||
$this->data['User']['lat'] = floatval($temp['lat']);
|
||||
$this->data['User']['long'] = floatval($temp['long']);
|
||||
$this->data['User']['tz'] = intval($temp['tz']);
|
||||
$this->data['User']['role'] = $user['User']['role'];
|
||||
|
||||
if (!preg_match("/^(http|https)\:\/\//i", $this->data['User']['website']) &&
|
||||
!empty($this->data['User']['website']))
|
||||
$this->User->invalidate('website');
|
||||
|
||||
if ($this->data['User']['password'] === $this->data['User']['confpassword'] &&
|
||||
!empty($this->data['User']['password'])) {
|
||||
$pass = $this->Hash->password($this->data['User']['password'], $user['User']['email']);
|
||||
$this->data['User']['password'] = $pass['pass'];
|
||||
$this->data['User']['salt'] = $pass['salt'];
|
||||
}
|
||||
|
||||
else if (empty($this->data['User']['password']) && empty($this->data['User']['confpassword'])) {
|
||||
$this->data['User']['password'] = $user['User']['password'];
|
||||
$this->data['User']['salt'] = $user['User']['salt'];
|
||||
}
|
||||
|
||||
else {
|
||||
$this->set('error', true);
|
||||
$this->User->invalidate('password');
|
||||
$this->User->invalidate('confpassword');
|
||||
}
|
||||
|
||||
if ($this->User->validates($this->data)) {
|
||||
if ($this->User->save($this->data)) {
|
||||
$sess = $this->User->findById($user['User']['id']);
|
||||
$this->redirect('/users/');
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$this->validateErrors($this->User);
|
||||
$this->data['User']['password'] = null;
|
||||
$this->data['User']['confpassword'] = null;
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function login() {
|
||||
if ($this->Session->Check('User'))
|
||||
$this->redirect('/users');
|
||||
|
||||
$this->pageTitle = 'Login';
|
||||
if (!empty($this->data)) {
|
||||
if (empty($this->data['User']['email']) || empty($this->data['User']['password']))
|
||||
$this->render();
|
||||
|
||||
$user = $this->User->findByEmail($this->data['User']['email']);
|
||||
$pass = sha1($this->data['User']['password'].$user['User']['salt']);
|
||||
|
||||
if ($user['User']['password'] == $pass) {
|
||||
if ($user['User']['active'] != 1) {
|
||||
$this->Session->setFlash('Your account hasn\'t been activated yet. Please
|
||||
check your email (including junk/spam folders)
|
||||
for your activation link, or click <a href="'
|
||||
.APP_BASE.'/users/recover/activate">here</a> to
|
||||
resend your activation details.', 'infoFlash');
|
||||
$this->render();
|
||||
}
|
||||
|
||||
else {
|
||||
if (isset($_SESSION['invite']))
|
||||
$this->Party->addGuest($user['User']['id'], $_SESSION['invite']);
|
||||
|
||||
$this->Session->write('User', $user['User']);
|
||||
$this->redirect('/users/');
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Session->setFlash('The email address and password you supplied do
|
||||
not match. Please try again.', 'errorFlash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function view($id = null) {
|
||||
if (!is_numeric($id))
|
||||
$this->redirect('/');
|
||||
|
||||
else {
|
||||
$user = $this->User->findById($id);
|
||||
$this->pageTitle = $user['User']['name'];
|
||||
$this->set('user', $user);
|
||||
if (GMAP_API_KEY != null && !empty($user['User']['lat']))
|
||||
$this->set('map', 'mapInit('.$user['User']['lat'].','.$user['User']['long'].','.$user['User']['zoom'].',\'stationary\');');
|
||||
|
||||
$this->Party->unbindModel(array('hasMany' => array('Comment')));
|
||||
$this->set('hparties', $this->User->hostOf($id));
|
||||
$att = $this->User->query('SELECT parties.id, parties.name
|
||||
FROM parties
|
||||
LEFT JOIN guests
|
||||
ON parties.id = guests.pid
|
||||
WHERE guests.uid = '.$id);
|
||||
$this->set('parties', $att);
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
$this->Session->destroy();
|
||||
$this->Session->delete('User');
|
||||
$this->redirect('/');
|
||||
}
|
||||
|
||||
function recover($aType = null, $aCode = null, $aId = null) {
|
||||
switch ($aType) {
|
||||
case "password":
|
||||
$this->pageTitle = "Password Recovery";
|
||||
$this->set('atitle', 'Password Recovery');
|
||||
$this->set('hideInput', false);
|
||||
$this->set('url', 'password');
|
||||
|
||||
if (!empty($this->data)) {
|
||||
$user = $this->User->findByEmail($this->data['User']['email']);
|
||||
|
||||
if (!isset($user['User']['email'])) {
|
||||
$this->Session->setFlash('Could not find a user with that email address. Please check it and try again.', 'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
else {
|
||||
$code = md5($user['User']['salt'].$user['User']['email'].$user['User']['password']);
|
||||
$message = array('from' => APP_NAME.' <'.APP_EMAIL.'>',
|
||||
'envelope' => APP_EMAIL,
|
||||
'to' => $user['User']['email'],
|
||||
'subject' => APP_NAME.' Password Request',
|
||||
'link' => APP_BASE.'/users/recover/password/'.$code.'/'.$user['User']['id'],
|
||||
'type' => 'prec');
|
||||
|
||||
$this->Mail->mail($message);
|
||||
$this->Mail->send();
|
||||
$this->Session->setFlash('An email has been sent to '.$user['User']['email'].' with reset instructions.', 'errorFlash');
|
||||
$this->redirect('users/login');
|
||||
}
|
||||
}
|
||||
|
||||
if ($aCode !== null && $aId !== null) {
|
||||
$this->set('hideInput', true);
|
||||
$this->set('reset', false);
|
||||
$user = $this->User->findById($aId);
|
||||
|
||||
if (!$user) {
|
||||
$this->Session->setFlash('Invalid request. Please check the URL and try again.', 'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
|
||||
if ($aCode == md5($user['User']['salt'].$user['User']['email'].$user['User']['password'])) {
|
||||
$this->set('reset', true);
|
||||
$this->set('code', $aCode."/".$aId);
|
||||
$this->render();
|
||||
}
|
||||
|
||||
else {
|
||||
$this->Session->setFlash('Invalid request. Please check the URL and try again.', 'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "activate":
|
||||
$this->pageTitle = 'Resend Activation Code';
|
||||
$this->set('atitle', 'Resend Activation Code');
|
||||
$this->set('hideInput', false);
|
||||
$this->set('url', 'activate');
|
||||
|
||||
if (!empty($this->data)) {
|
||||
$user = $this->User->findByEmail($this->data['User']['email']);
|
||||
|
||||
if (!$user) {
|
||||
$this->Session->setFlash('Could not find a user with that email address. Please check it and try again.', 'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
|
||||
if ($user['User']['active'] == 1)
|
||||
$this->redirect('/users/login');
|
||||
|
||||
else {
|
||||
$message = array('from' => APP_NAME.' <'.APP_EMAIL.'>',
|
||||
'envelope' => APP_EMAIL,
|
||||
'to' => $this->data['User']['email'],
|
||||
'subject' => 'Your '.APP_NAME.' Registration',
|
||||
'link' => APP_BASE.'/users/activate/'.$user['User']['active'],
|
||||
'type' => 'act');
|
||||
$this->Mail->mail($message);
|
||||
$this->Mail->send();
|
||||
$this->Session->setFlash('Your activation code has been resent.', 'infoFlash');
|
||||
$this->redirect('users/login');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "reset":
|
||||
if ($aCode !== null && $aId !== null) {
|
||||
if (!empty($this->data)) {
|
||||
$user = $this->User->findById($aId);
|
||||
if (!$user) {
|
||||
$this->Session->setFlash('Invalid request. Please check the URL and try again.', 'errorFlash');
|
||||
$this->render();
|
||||
}
|
||||
|
||||
if ($aCode == md5($user['User']['salt'].$user['User']['email'].$user['User']['password'])) {
|
||||
$string = $user['User']['email'] . uniqid(rand(), true) . $this->data['User']['password'];
|
||||
$this->data['User']['salt'] = substr(md5($string), 0, 9);
|
||||
$this->data['User']['password'] = sha1($this->data['User']['password'] . $this->data['User']['salt']);
|
||||
$this->data['User']['id'] = $aId;
|
||||
if ($this->User->save($this->data)) {
|
||||
$this->Session->setFlash('Your password has been reset.', 'infoFlash');
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->redirect('/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function activate($aKey = null) {
|
||||
if ($aKey == null)
|
||||
$this->redirect('/');
|
||||
|
||||
else {
|
||||
$user = $this->User->findByActive($aKey);
|
||||
if (empty($user['User']['id'])) {
|
||||
$this->Session->setFlash('Your account could not be activated. Please make
|
||||
sure the URL entered is correct and try again.', 'errorFlash');
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
|
||||
else {
|
||||
$this->data = $user;
|
||||
$this->data['User']['active'] = 1;
|
||||
|
||||
if ($this->User->save($this->data)) {
|
||||
$this->Session->setFlash('Your account was successfully activated.', 'infoFlash');
|
||||
$this->redirect('/users/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: index.php,v 1.3 2006-10-08 03:39:21 reed%reedloden.com Exp $ */
|
||||
/**
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP v 0.10.0.1076
|
||||
* @version $Revision: 1.3 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-10-08 03:39:21 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
|
||||
?>
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Admin extends AppModel {
|
||||
var $name = 'Admin';
|
||||
var $useTable = "parties";
|
||||
}
|
||||
?>
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Comment extends AppModel {
|
||||
var $name = 'Comment';
|
||||
|
||||
var $validate = array(
|
||||
'text' => "/^\S/"
|
||||
);
|
||||
|
||||
function canComment($pid, $uid) {
|
||||
$status = $this->query('SELECT owner, guestcomments FROM parties WHERE id = '.$pid);
|
||||
$guest = null;
|
||||
if ($status[0]['parties']['owner'] != $uid)
|
||||
$guest = $this->query('SELECT uid FROM guests WHERE pid = '.$pid.' AND uid = '.$uid);
|
||||
|
||||
if ($status[0]['parties']['guestcomments'] == 1) {
|
||||
if (!empty($guest[0]['guests']['uid']) || $uid == $status[0]['parties']['owner'])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Feed extends AppModel {
|
||||
var $name = 'Feeds';
|
||||
var $useTable = "parties";
|
||||
|
||||
function getComments($aParty) {
|
||||
$rv = $this->query("SELECT * FROM comments WHERE assoc = ".$aParty." LIMIT 10");
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function getUserCount() {
|
||||
$rv = $this->query("SELECT COUNT(*) FROM users");
|
||||
return $rv[0][0]['COUNT(*)'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Guest extends AppModel {
|
||||
var $name = 'Guest';
|
||||
}
|
||||
?>
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Page extends AppModel {
|
||||
var $name = 'Page';
|
||||
var $useTable = 'parties';
|
||||
|
||||
function getUsers() {
|
||||
$rv = $this->query("SELECT COUNT(*) FROM users");
|
||||
return $rv[0][0]["COUNT(*)"];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class Party extends AppModel {
|
||||
var $name = 'Party';
|
||||
var $validate = array(
|
||||
'name' => "/^\S/",
|
||||
'einvite' => VALID_EMAIL,
|
||||
'duration' => VALID_NUMBER
|
||||
);
|
||||
|
||||
function getComments($pid) {
|
||||
$rv = $this->query("SELECT users.id AS uid, users.name,
|
||||
comments.id AS cid, comments.time, comments.text
|
||||
FROM users, parties, comments
|
||||
WHERE comments.assoc = ".$pid."
|
||||
AND users.id = comments.owner
|
||||
AND parties.id = ".$pid."
|
||||
ORDER BY cid ASC");
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function getHost($uid) {
|
||||
$rv = $this->query("SELECT name FROM users WHERE id = ".$uid);
|
||||
return @$rv[0]['users']['name'];
|
||||
}
|
||||
|
||||
function isGuest($pid, $uid) {
|
||||
$rv = $this->query('SELECT id FROM guests WHERE uid = '.$uid.' AND pid = '.$pid);
|
||||
if (!empty($rv[0]['guests']['id']))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function getGuests($pid) {
|
||||
$rv = $this->query("SELECT users.id, users.name, users.email, guests.invited
|
||||
FROM users
|
||||
LEFT JOIN guests
|
||||
ON users.id = guests.uid
|
||||
WHERE guests.pid = ".$pid);
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function rsvp($pid, $uid) {
|
||||
$party = $this->findById($pid);
|
||||
if (!empty($party['Party']['id']) && !$this->isGuest($pid, $uid)) {
|
||||
$this->query("INSERT INTO guests (id, pid, uid, invited)
|
||||
VALUES (NULL, ".$party['Party']['id'].", ".$uid.", 0)");
|
||||
}
|
||||
}
|
||||
|
||||
function unrsvp($pid, $uid) {
|
||||
$party = $this->findById($pid);
|
||||
if (!empty($party['Party']['id']) && $this->isGuest($pid, $uid)) {
|
||||
$this->query('DELETE FROM guests WHERE uid = '.$uid.' AND pid = '.$pid);
|
||||
}
|
||||
}
|
||||
|
||||
function addGuest($uid, $icode) {
|
||||
$party = $this->findByInvitecode($icode);
|
||||
if (!empty($party['Party']['id'])) {
|
||||
$check = $this->query('SELECT uid FROM guests WHERE uid = '.$uid.'
|
||||
AND pid = '.$party['Party']['id']);
|
||||
if (empty($check[0]['guests']['uid']) && $uid != $party['Party']['owner']) {
|
||||
$this->query("INSERT INTO guests (id, pid, uid, invited)
|
||||
VALUES (NULL, ".$party['Party']['id'].", ".$uid.", 1)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findByInvitecode($icode) {
|
||||
$rv = $this->query('SELECT * FROM parties AS Party WHERE invitecode = "'.$icode.'" LIMIT 1');
|
||||
return @$rv[0];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class User extends AppModel {
|
||||
var $name = 'User';
|
||||
var $validate = array(
|
||||
'email' => VALID_EMAIL,
|
||||
'name' => "/^\S/"
|
||||
);
|
||||
|
||||
function memberOf($uid) {
|
||||
$rv = $this->query('SELECT parties.id, parties.name FROM guests, parties WHERE guests.uid = '.$uid.' AND parties.id = guests.pid');
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function hostOf($uid) {
|
||||
$rv = $this->query('SELECT id, name FROM parties WHERE owner = '.$uid);
|
||||
return $rv;
|
||||
}
|
||||
|
||||
function invitedTo($uid) {
|
||||
$rv = $this->query('SELECT parties.id, parties.name FROM guests, parties WHERE guests.uid = '.$uid.' AND parties.id = guests.pid AND guests.invited = 1');
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
?>
|
||||
199
mozilla/webtools/partytool/vendors/webServices.php
vendored
199
mozilla/webtools/partytool/vendors/webServices.php
vendored
@@ -1,199 +0,0 @@
|
||||
<?php
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla Party Tool
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ryan Flint <rflint@dslr.net>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
class webServices {
|
||||
|
||||
var $userid;
|
||||
var $host;
|
||||
var $randomize;
|
||||
|
||||
function webServices($data) {
|
||||
switch ($data['type']) {
|
||||
case "flickr":
|
||||
$this->host = "api.flickr.com";
|
||||
|
||||
if (array_key_exists('userid', $data))
|
||||
$this->userid = $data['userid'];
|
||||
|
||||
if (array_key_exists('randomize', $data))
|
||||
$this->randomize = $data['randomize'];
|
||||
|
||||
if (array_key_exists('username', $data)) {
|
||||
$head = "GET /services/rest/?method=flickr.people.findByUsername&api_key=".FLICKR_API_KEY."&username=".$data['username']." HTTP/1.1\r\n";
|
||||
$head .= "Host: ".$this->host."\r\n";
|
||||
$head .= "Connection: Close\r\n\r\n";
|
||||
|
||||
if ($results = $this->fetchResults($head)) {
|
||||
preg_match('/nsid=\"(.*)\"/', $results, $matches);
|
||||
if ($matches[1]) {
|
||||
$this->userid = $matches[1];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "gsuggest":
|
||||
$this->host = "api.google.com";
|
||||
break;
|
||||
|
||||
case "geocode":
|
||||
$this->host = "maps.google.com";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getFlickrId() {
|
||||
return $this->userid;
|
||||
}
|
||||
|
||||
function fetchPhotos($tags, $num_results, $single_user) {
|
||||
$params = array('api_key' => FLICKR_API_KEY,
|
||||
'method' => 'flickr.photos.search',
|
||||
'format' => 'php_serial',
|
||||
'tags' => $tags,
|
||||
'per_page' => $num_results);
|
||||
|
||||
if ($single_user)
|
||||
$params['user_id'] = $this->userid;
|
||||
|
||||
$encoded_params = array();
|
||||
foreach ($params as $k => $v)
|
||||
$encoded_params[] = urlencode($k).'='.urlencode($v);
|
||||
|
||||
$head = 'GET /services/rest/?'.implode('&', $encoded_params)." HTTP/1.1 \r\n";
|
||||
$head .= 'Host: '.$this->host."\r\n";
|
||||
$head .= "Connection: Close\r\n\r\n";
|
||||
|
||||
if ($results = $this->fetchResults($head)) {
|
||||
$resp = split("\r\n\r\n", $results);
|
||||
$data = unserialize($resp[1]);
|
||||
|
||||
if ($data['stat'] == 'ok') {
|
||||
$arr = array();
|
||||
for ($i = 0; $i < count($data['photos']['photo']); $i++) {
|
||||
$p = $data['photos']['photo'][$i];
|
||||
$arr[$i] = array('id' => $p['id'],
|
||||
'owner' => $p['owner'],
|
||||
'secret' => $p['secret'],
|
||||
'server' => $p['server'],
|
||||
'farm' => $p['farm'],
|
||||
'title' => $p['title']);
|
||||
}
|
||||
|
||||
if ($this->randomize) {
|
||||
// Randomize the results
|
||||
shuffle($arr);
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
function GSuggest($phrase) {
|
||||
$soapy = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
|
||||
<SOAP-ENV:Body>
|
||||
<doSpellingSuggestion xmlns="urn:GoogleSearch">
|
||||
<key xsi:type="xsd:string">'.GSEARCH_API_KEY.'</key>
|
||||
<phrase xsi:type="xsd:string">'.$phrase.'</phrase>
|
||||
</doSpellingSuggestion>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>';
|
||||
|
||||
$head = "POST /search/beta2 HTTP/1.1\r\n";
|
||||
$head .= "Host: api.google.com\r\n";
|
||||
$head .= "MessageType: CALL\r\n";
|
||||
$head .= "Content-type: text/xml\r\n";
|
||||
$head .= "Content-length: ".strlen($soapy)."\r\n";
|
||||
$head .= "Connection: Close\r\n\r\n";
|
||||
$head .= $soapy;
|
||||
|
||||
if ($results = $this->fetchResults($head)) {
|
||||
if (preg_match('/return xsi:type="xsd:string">(.*)</', $results, $matches))
|
||||
return $matches[1];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function geocode($query) {
|
||||
$head = "GET /maps/geo?q=".urlencode($query)."&output=xml&key=".GMAP_API_KEY." HTTP/1.1\r\n";
|
||||
$head .= "Host: maps.google.com\r\n";
|
||||
$head .= "Connection: Close\r\n\r\n";
|
||||
|
||||
if ($results = $this->fetchResults($head)) {
|
||||
if (stristr($results, '<code>200</code>')) {
|
||||
preg_match('/coordinates>(.*)</', $results, $matches);
|
||||
$ll = explode(',', $matches[1]);
|
||||
$rv = array('lat' => $ll[1], 'lng' => $ll[0]);
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function fetchResults($headers) {
|
||||
$fs = fsockopen($this->host, 80, $errno, $errstr, 30);
|
||||
if (!$fs)
|
||||
return 0;
|
||||
|
||||
else {
|
||||
fwrite($fs, $headers);
|
||||
stream_set_timeout($fs, 2);
|
||||
|
||||
$buffer = null;
|
||||
while (!feof($fs))
|
||||
$buffer .= fgets($fs, 128);
|
||||
|
||||
fclose($fs);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,18 +0,0 @@
|
||||
<h1>Comments</h1>
|
||||
<p>Switch view to: <a href="<?php echo $html->url('/admin/'); ?>">Parties»</a> <a href="<?php echo $html->url('/admin/users'); ?>">Users»</a></p>
|
||||
<table>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>Text</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php foreach($comments as $comment): ?>
|
||||
<tr>
|
||||
<td><a href="<?php echo $html->url('/parties/view/'.$comment['Comment']['assoc'].'#c'.$comment['Comment']['id']); ?>"><?php echo $comment['Comment']['id']; ?></a></td>
|
||||
<td><?php echo $comment['Comment']['text']; ?></td>
|
||||
<td><a href="<?php echo $html->url('/admin/edit/comment/'.$comment['Comment']['id']); ?>">Edit</a></td>
|
||||
<td><a href="<?php echo $html->url('/admin/delete/comment/'.$comment['Comment']['id']); ?>" onclick="return confirm('Delete comment <?php echo $comment['Comment']['id']; ?>?')">Delete</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php if (isset($user)): ?>
|
||||
<h1><?php echo $user['User']['name'].' (<a href="'.$html->url('/users/view/'.$user['User']['id']).'">'.$user['User']['id']; ?></a>)</h1>
|
||||
<form class="fxform" action="<?php echo $html->url('/admin/edit/user/'.$user['User']['id']); ?>" method="post">
|
||||
<div>
|
||||
<label for="UserName" class="label-large">Name:</label>
|
||||
<?php echo $html->input('User/name', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserRole" class="label-large">Admin privileges:</label>
|
||||
<?php echo $html->checkbox('User/role'); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserEmail" class="label-large">Email address:</label>
|
||||
<?php echo $html->input('User/email', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserWebsite" class="label-large">Website:</label>
|
||||
<?php echo $html->input('User/website', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserActive" class="label-large">Activation code:</label>
|
||||
<?php echo $html->input('User/active', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="location" class="label-large">Location:</label>
|
||||
<?php echo $html->input('User/location', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserShowemail" class="label-large">Show email:</label>
|
||||
<?php echo $html->checkbox('User/showemail'); ?><br/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserShowloc" class="label-large">Show location:</label>
|
||||
<?php echo $html->checkbox('User/showloc'); ?><br/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="UserShowmap" class="label-large">Show map:</label>
|
||||
<?php echo $html->checkbox('User/showmap'); ?><br/>
|
||||
</div>
|
||||
<?php echo $html->hidden('User/id', array('value' => $user['User']['id'])).$html->submit('Submit'); ?>
|
||||
</form>
|
||||
|
||||
<?php endif; if (isset($party)): ?>
|
||||
<h1><?php echo $party['Party']['name'].' (<a href="'.$html->url('/parties/view/'.$party['Party']['id']).'">'.$party['Party']['id']; ?></a>)</h1>
|
||||
<form class="fxform" action="<?php echo $html->url('/admin/edit/party/'.$party['Party']['id']); ?>" method="post">
|
||||
<div>
|
||||
<label for="PartyOwner" class="label-large">Party Owner:</label>
|
||||
<?php echo $html->input('Party/owner', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyName" class="label-large">Party Name:</label>
|
||||
<?php echo $html->input('Party/name', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyVname" class="label-large">Venue Name:</label>
|
||||
<?php echo $html->input('Party/vname', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyWebsite" class="label-large">Web site:</label>
|
||||
<?php echo $html->input('Party/website', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyAddress" class="label-large">Address:</label>
|
||||
<?php echo $html->input('Party/address', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyDate" class="label-large">Date:</label>
|
||||
<?php echo $html->input('Party/date', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyNotes" class="label-large">Additional Notes:</label>
|
||||
<?php echo $html->textarea('Party/notes', array('rows' => 10, 'cols' => 50)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyConfirmed" class="label-large">Time:</label>
|
||||
<?php echo $html->radio('Party/confirmed', array(0 => 'Tentative', 1 => 'Confirmed')); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyDuration" class="label-large">Duration (in hours):</label>
|
||||
<?php echo $html->input('Party/duration', array('size' => 5)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyCanceled" class="label-large">Canceled:</label>
|
||||
<?php echo $html->checkbox('Party/canceled'); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyUseflickr" class="label-large">Use Flickr:</label>
|
||||
<?php echo $html->checkbox('Party/useflickr'); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyFlickrperms" class="label-large">Show:</label>
|
||||
<?php echo $html->radio('Party/flickrperms', array(0 => 'Only my photos', 1 => 'Anyone\'s photos')); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyFlickrusr" class="label-large">Flickr username:</label>
|
||||
<?php echo $html->input('Party/flickrusr', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyFlickrusr" class="label-large">Flickr id:</label>
|
||||
<?php echo $html->input('Party/flickrid', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyInviteonly" class="label-large">Invite only:</label>
|
||||
<?php echo $html->checkbox('Party/inviteonly'); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="PartyGuestcomments" class="label-large">Limit comments to party guests only:</label>
|
||||
<?php echo $html->checkbox('Party/guestcomments'); ?>
|
||||
</div>
|
||||
<br/>
|
||||
<?php echo $html->hidden('Party/id', array('value' => $party['Party']['id'])).$html->submit('Submit'); ?>
|
||||
</form>
|
||||
|
||||
<?php endif; if(isset($comment)): ?>
|
||||
<h1>Comment <?php echo '<a href="'.$html->url('/parties/view/'.$comment['Comment']['assoc'].'#c'.$comment['Comment']['id']).'">#'.$comment['Comment']['id']; ?></a> by <?php echo '<a href="'.$html->url('/users/view/'.$comment['Comment']['owner']).'">'.$owner; ?></a></h1>
|
||||
<form class="fxform" action="<?php echo $html->url('/admin/edit/comment/'.$comment['Comment']['id']); ?>" method="post">
|
||||
<div>
|
||||
<label for="CommentAssoc" class="label-large">Party:</label>
|
||||
<?php echo $html->input('Comment/assoc', array('size' => 40)); ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="CommentText" class="label-large">Text:</label>
|
||||
<?php echo $html->textarea('Comment/text', array('rows' => 10, 'cols' => 50)); ?>
|
||||
</div>
|
||||
<?php echo $html->hidden('Comment/id', array('value' => $comment['Comment']['id'])).$html->submit('Submit'); ?>
|
||||
</form>
|
||||
|
||||
<?php endif; ?>
|
||||
@@ -1,18 +0,0 @@
|
||||
<h1>Parties</h1>
|
||||
<p>Switch view to: <a href="<?php echo $html->url('/admin/users'); ?>">Users»</a> <a href="<?php echo $html->url('/admin/comments'); ?>">Comments»</a></p>
|
||||
<table>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>Name</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php foreach($parties as $party): ?>
|
||||
<tr>
|
||||
<td><a href="<?php echo $html->url('/parties/view/'.$party['Party']['id']); ?>"><?php echo $party['Party']['id']; ?></a></td>
|
||||
<td><?php echo $party['Party']['name']; ?></td>
|
||||
<td><a href="<?php echo $html->url('/admin/edit/party/'.$party['Party']['id']); ?>">Edit</a></td>
|
||||
<td><a href="<?php echo $html->url('/admin/delete/party/'.$party['Party']['id']); ?>" onclick="return confirm('Delete party <?php echo $party['Party']['id']; ?>?')">Delete</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user