~ubuntu-branches/ubuntu/natty/gnome-keyring/natty-proposed

« back to all changes in this revision

Viewing changes to pkcs11/gck/gck-secret-key.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-09-01 12:54:04 UTC
  • mfrom: (1.1.64 upstream)
  • Revision ID: james.westby@ubuntu.com-20100901125404-3d96lh3oo4karbv3
Tags: 2.92.92.is.2.31.91-0ubuntu1
* New upstream release
* debian/control:
  - Drop build-depends on libgconf2-dev
  - Build-depend on dh-autoreconf, gnome-common
* debian/rules:
  - Use autoreconf.mk
* debian/gnome-keyring.install:
  - No longer provides a gconf schema
* debian/libgcr0.symbols:
  - Updated
* debian/patches/90_git_pam_headers.patch:
  - Fix incorrect PAM header check
* debian/patches/05_login_unlock_string.patch:
* debian/patches/90_git_keyring_encoding.patch:
  - Applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * gnome-keyring
3
 
 *
4
 
 * Copyright (C) 2008 Stefan Walter
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU Lesser General Public License as
8
 
 * published by the Free Software Foundation; either version 2.1 of
9
 
 * the License, or (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful, but
12
 
 * 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 program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
 
 * 02111-1307, USA.
20
 
 */
21
 
 
22
 
#include "config.h"
23
 
 
24
 
#include "pkcs11/pkcs11.h"
25
 
 
26
 
#include "gck-attributes.h"
27
 
#include "gck-crypto.h"
28
 
#include "gck-secret-key.h"
29
 
#include "gck-session.h"
30
 
#include "gck-util.h"
31
 
 
32
 
struct _GckSecretKeyPrivate {
33
 
        gpointer id;
34
 
        gsize n_id;
35
 
};
36
 
 
37
 
G_DEFINE_TYPE (GckSecretKey, gck_secret_key, GCK_TYPE_OBJECT);
38
 
 
39
 
/* -----------------------------------------------------------------------------
40
 
 * INTERNAL
41
 
 */
42
 
 
43
 
/* -----------------------------------------------------------------------------
44
 
 * PUBLIC_SECRET_KEY
45
 
 */
46
 
 
47
 
static CK_RV
48
 
gck_secret_key_real_get_attribute (GckObject *base, GckSession *session, CK_ATTRIBUTE* attr)
49
 
{
50
 
        GckSecretKey *self = GCK_SECRET_KEY (base);
51
 
 
52
 
        switch (attr->type)
53
 
        {
54
 
        case CKA_CLASS:
55
 
                return gck_attribute_set_ulong (attr, CKO_SECRET_KEY);
56
 
 
57
 
        case CKA_SENSITIVE:
58
 
        case CKA_ENCRYPT:
59
 
        case CKA_DECRYPT:
60
 
        case CKA_SIGN:
61
 
        case CKA_VERIFY:
62
 
        case CKA_WRAP:
63
 
        case CKA_UNWRAP:
64
 
        case CKA_DERIVE:
65
 
                return gck_attribute_set_bool (attr, FALSE);
66
 
 
67
 
        case CKA_EXTRACTABLE:
68
 
                return gck_attribute_set_bool (attr, TRUE);
69
 
 
70
 
        case CKA_ALWAYS_SENSITIVE:
71
 
                return gck_attribute_set_bool (attr, FALSE);
72
 
 
73
 
        case CKA_NEVER_EXTRACTABLE:
74
 
                return gck_attribute_set_bool (attr, FALSE);
75
 
 
76
 
        case CKA_WRAP_WITH_TRUSTED:
77
 
                return gck_attribute_set_bool (attr, FALSE);
78
 
 
79
 
        case CKA_TRUSTED:
80
 
                return gck_attribute_set_bool (attr, FALSE);
81
 
 
82
 
        case CKA_WRAP_TEMPLATE:
83
 
        case CKA_UNWRAP_TEMPLATE:
84
 
                return CKR_ATTRIBUTE_TYPE_INVALID;
85
 
 
86
 
        case CKA_START_DATE:
87
 
        case CKA_END_DATE:
88
 
                return gck_attribute_set_empty (attr);
89
 
 
90
 
        case CKA_LOCAL:
91
 
                return gck_attribute_set_bool (attr, FALSE);
92
 
 
93
 
        case CKA_ID:
94
 
                return gck_attribute_set_data (attr, self->pv->id, self->pv->n_id);
95
 
 
96
 
        case CKA_KEY_GEN_MECHANISM:
97
 
                return gck_attribute_set_ulong (attr, CK_UNAVAILABLE_INFORMATION);
98
 
        };
99
 
 
100
 
        return GCK_OBJECT_CLASS (gck_secret_key_parent_class)->get_attribute (base, session, attr);
101
 
}
102
 
 
103
 
static void
104
 
gck_secret_key_real_create_attributes (GckObject *object, GckSession *session, GckTransaction *transaction,
105
 
                                       CK_ATTRIBUTE *attrs, CK_ULONG n_attrs)
106
 
{
107
 
        GckSecretKey *self = GCK_SECRET_KEY (object);
108
 
        CK_ATTRIBUTE_PTR id;
109
 
 
110
 
        if (!self->pv->n_id) {
111
 
                id = gck_attributes_find (attrs, n_attrs, CKA_ID);
112
 
                if (id == NULL) {
113
 
                        self->pv->id = NULL;
114
 
                        self->pv->n_id = 0;
115
 
                } else {
116
 
                        self->pv->id = g_memdup (id->pValue, id->ulValueLen);
117
 
                        self->pv->n_id = id->ulValueLen;
118
 
                        gck_attribute_consume (id);
119
 
                }
120
 
        }
121
 
}
122
 
 
123
 
static void
124
 
gck_secret_key_init (GckSecretKey *self)
125
 
{
126
 
        self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCK_TYPE_SECRET_KEY, GckSecretKeyPrivate);
127
 
}
128
 
 
129
 
static void
130
 
gck_secret_key_finalize (GObject *obj)
131
 
{
132
 
        GckSecretKey *self = GCK_SECRET_KEY (obj);
133
 
 
134
 
        g_free (self->pv->id);
135
 
        self->pv->id = NULL;
136
 
        self->pv->n_id = 0;
137
 
 
138
 
        G_OBJECT_CLASS (gck_secret_key_parent_class)->finalize (obj);
139
 
}
140
 
 
141
 
static void
142
 
gck_secret_key_class_init (GckSecretKeyClass *klass)
143
 
{
144
 
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
145
 
        GckObjectClass *gck_class = GCK_OBJECT_CLASS (klass);
146
 
 
147
 
        gck_secret_key_parent_class = g_type_class_peek_parent (klass);
148
 
 
149
 
        gobject_class->finalize = gck_secret_key_finalize;
150
 
 
151
 
        gck_class->get_attribute = gck_secret_key_real_get_attribute;
152
 
        gck_class->create_attributes = gck_secret_key_real_create_attributes;
153
 
 
154
 
        g_type_class_add_private (klass, sizeof (GckSecretKeyPrivate));
155
 
}
156
 
 
157
 
/* -----------------------------------------------------------------------------
158
 
 * PUBLIC
159
 
 */
160