📄 p7dconn.c
字号:
/* -*- 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 "p7dconn.h"#include "serv.h"#include "servimpl.h"#include "ssmerrs.h"#include "newproto.h"#include "messages.h"#include "collectn.h"#include "secmime.h"/* Shorthand macros for inherited classes */#define SSMRESOURCE(conn) (&(conn)->super.super.super)#define SSMCONNECTION(conn) (&(conn)->super.super)#define SSMDATACONNECTION(conn) (&(conn)->super)#define SSM_PARENT_CONN(conn) ((SSMControlConnection*)((conn)->super.super.m_parent))void SSMP7DecodeConnection_ServiceThread(void * arg);SSMStatus SSMP7DecodeConnection_StartDecoding(SSMP7DecodeConnection *conn);/* callbacks for PKCS7 decoder */void SSMP7DecodeConnection_ContentCallback(void *arg, const char *buf, unsigned long len);PK11SymKey * SSMP7DecodeConnection_GetDecryptKey(void *arg, SECAlgorithmID *algid);PRBool SSMP7DecodeConnection_DecryptionAllowed(SECAlgorithmID *algid, PK11SymKey *bulkkey);SECItem * SSMP7DecodeConnection_GetPasswordKey(void *arg, SECKEYKeyDBHandle *handle);SSMStatus SSMP7DecodeConnection_Create(void *arg, SSMControlConnection * connection, SSMResource **res){ SSMStatus rv = PR_SUCCESS; SSMP7DecodeConnection *conn; *res = NULL; /* in case we fail */ conn = (SSMP7DecodeConnection *) PR_CALLOC(sizeof(SSMP7DecodeConnection)); if (!conn) goto loser; SSMRESOURCE(conn)->m_connection = connection; rv = SSMP7DecodeConnection_Init(conn, (SSMInfoP7Decode*) arg, SSM_RESTYPE_PKCS7_DECODE_CONNECTION); if (rv != PR_SUCCESS) goto loser; SSMP7DecodeConnection_Invariant(conn); *res = SSMRESOURCE(conn); return PR_SUCCESS; loser: if (rv == PR_SUCCESS) rv = PR_FAILURE; if (conn) { SSM_ShutdownResource(SSMRESOURCE(conn), rv); /* force destroy */ SSM_FreeResource(SSMRESOURCE(conn)); } return rv;}SSMStatus SSMP7DecodeConnection_Init(SSMP7DecodeConnection *conn, SSMInfoP7Decode *info, SSMResourceType type){ SSMStatus rv = PR_SUCCESS; rv = SSMDataConnection_Init(SSMDATACONNECTION(conn), info->ctrl, type); if (rv != PR_SUCCESS) goto loser; /* Start the decoder */ if (SSMP7DecodeConnection_StartDecoding(conn) != SSM_SUCCESS) { goto loser; } /* Save the client UI context */ SSMRESOURCE(conn)->m_clientContext = info->clientContext; /* Spin the service thread. */ SSM_DEBUG("Creating decoder service thread.\n"); SSM_GetResourceReference(SSMRESOURCE(conn)); SSMDATACONNECTION(conn)->m_dataServiceThread = SSM_CreateThread(SSMRESOURCE(conn), SSMP7DecodeConnection_ServiceThread); if (SSMDATACONNECTION(conn)->m_dataServiceThread == NULL) { goto loser; } return PR_SUCCESS; loser: if (rv == PR_SUCCESS) rv = PR_FAILURE; return rv;}SSMStatusSSMP7DecodeConnection_FinishDecoding(SSMP7DecodeConnection *conn){ SEC_PKCS7ContentInfo *p7info = NULL; SSMResourceID resID; SSMStatus rv = SSM_SUCCESS; if (conn->m_cinfo) { SSM_FreeResource(&conn->m_cinfo->super); conn->m_cinfo = NULL; } if (conn->m_context) { p7info = SEC_PKCS7DecoderFinish(conn->m_context); if (!p7info) { conn->m_error = PR_GetError(); } conn->m_context = NULL; if (p7info) { rv = SSM_CreateResource(SSM_RESTYPE_PKCS7_CONTENT_INFO, p7info, SSM_PARENT_CONN(conn), &resID, (SSMResource **) &conn->m_cinfo); } else rv = PR_FAILURE; } return rv;}SSMStatus SSMP7DecodeConnection_StartDecoding(SSMP7DecodeConnection *conn){ PR_ASSERT(conn->m_context == NULL); SSM_LockResource(SSMRESOURCE(conn)); if (conn->m_context) SSMP7DecodeConnection_FinishDecoding(conn); conn->m_context = SEC_PKCS7DecoderStart(SSMP7DecodeConnection_ContentCallback, conn, SSMP7DecodeConnection_GetPasswordKey, conn, SSMP7DecodeConnection_GetDecryptKey, conn, SSMP7DecodeConnection_DecryptionAllowed); SSM_UnlockResource(SSMRESOURCE(conn)); /* Did we get a context */ if (!conn->m_context) { conn->m_error = PR_GetError(); return PR_FAILURE; } else { return PR_SUCCESS; }}SSMStatus SSMP7DecodeConnection_Destroy(SSMResource *res, PRBool doFree){ SSMP7DecodeConnection *conn = (SSMP7DecodeConnection *) res; if (doFree) SSM_DEBUG("SSMHashConnection_Destroy called.\n"); /* We should be shut down. */ PR_ASSERT(res->m_threadCount == 0); /* Destroy our fields. */ SSM_LockResource(SSMRESOURCE(conn)); if (conn->m_context) SSMP7DecodeConnection_FinishDecoding(conn); if (conn->m_cinfo) { SSM_FreeResource(&conn->m_cinfo->super); conn->m_cinfo = NULL; } SSM_UnlockResource(SSMRESOURCE(conn)); /* Destroy superclass fields. */ SSMDataConnection_Destroy(SSMRESOURCE(conn), PR_FALSE); /* Free the connection object if asked. */ if (doFree) PR_DELETE(conn); return PR_SUCCESS;}voidSSMP7DecodeConnection_Invariant(SSMP7DecodeConnection *conn){ SSMDataConnection_Invariant(SSMDATACONNECTION(conn)); /* our specific invariants */ SSM_LockResource(SSMRESOURCE(conn)); /* check class */ PR_ASSERT(SSM_IsAKindOf(SSMRESOURCE(conn), SSM_RESTYPE_PKCS7_DECODE_CONNECTION)); /* we should not be simultaneously decoded and decoding */ if (conn->m_context) PR_ASSERT(conn->m_cinfo == NULL); SSM_UnlockResource(SSMRESOURCE(conn));}SSMStatus SSMP7DecodeConnection_Shutdown(SSMResource *arg, SSMStatus status){ SSMStatus rv = SSM_SUCCESS; /* Call our superclass shutdown. */ rv = SSMDataConnection_Shutdown(arg, status); return rv;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -