source: murachi/esteidfirefoxplugin/firefox/cert-class.c @ f326ef1

Last change on this file since f326ef1 was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Estonian ID card plugin for web browsers
3 *
4 * Copyright (C) 2010-2011 Codeborne <info@codeborne.com>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 *
20 */
21
22#include <stdlib.h>
23#include "cert-class.h"
24#include "plugin-class.h"
25#include "esteid_error.h"
26
27extern NPNetscapeFuncs* browserFunctions;
28extern bool allowedSite;
29extern char EstEID_error[1024];
30extern int EstEID_errorCode;
31
32
33NPObject *certAllocate(NPP npp, NPClass *theClass) {
34        return(NPObject *)malloc(sizeof(CertInstance));
35}
36
37void certDeallocate(CertInstance *obj) {
38        EstEID_mapFree(obj->certInfo);
39        free(obj);
40}
41
42void certInvalidate() {
43}
44
45bool certInvokeDefault(CertInstance *obj, NPVariant *args, uint32_t argCount, NPVariant *result) {
46        return false;
47}
48
49bool certSetProperty(CertInstance *obj, NPIdentifier name, const NPVariant *variant) {
50        return false;
51}
52
53
54bool certHasProperty(NPClass *theClass, NPIdentifier name) {
55        FAIL_IF_NOT_ALLOWED_SITE
56        static char *certProperties[] = {"id", "cert", "CN", "issuerCN", "keyUsage", "validFrom", "validTo", "certSerialNumber", "certificateAsPEM", "certificateAsHex"};
57        for (int i = 0; i < sizeof(certProperties) / sizeof(char *); i++) {
58                if (isSameIdentifier(name, certProperties[i])) return true;
59        }
60        return false;
61}
62
63bool certGetProperty(CertInstance *obj, NPIdentifier name, NPVariant *variant) {
64        NPUTF8* nameString = browserFunctions->utf8fromidentifier(name);
65        EstEID_log("name=%s", (char *)nameString);
66        const char *result = EstEID_mapGet(obj->certInfo, EstEID_getCertPropertyName(nameString));
67        browserFunctions->memfree(nameString);
68        if (result) return copyStringToNPVariant(result, variant);
69        return false;
70}
71
72bool certHasMethod(NPObject *npobj, NPIdentifier name) {
73        return isSameIdentifier(name, "toString");
74}
75
76bool certInvoke(CertInstance *obj, NPIdentifier name, NPVariant *args, uint32_t argCount, NPVariant *result) {
77        if (isSameIdentifier(name, "toString")) {
78                return certGetProperty(obj, browserFunctions->getstringidentifier("CN"), result);
79        }
80        return false;
81}
82
83static NPClass _class = {
84    NP_CLASS_STRUCT_VERSION,
85    (NPAllocateFunctionPtr) certAllocate,
86    (NPDeallocateFunctionPtr) certDeallocate,
87    (NPInvalidateFunctionPtr) certInvalidate,
88    (NPHasMethodFunctionPtr) certHasMethod,
89    (NPInvokeFunctionPtr) certInvoke,
90    (NPInvokeDefaultFunctionPtr) certInvokeDefault,
91    (NPHasPropertyFunctionPtr) certHasProperty,
92    (NPGetPropertyFunctionPtr) certGetProperty,
93    (NPSetPropertyFunctionPtr) certSetProperty,
94};
95
96NPClass *certClass() {
97        return &_class;
98}
99
Note: See TracBrowser for help on using the repository browser.