summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java
blob: 7fd33f95f126711ff65bf9a3f040cfc8f16f35c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.cert;


import java.awt.*;
import java.io.*;
import java.util.*;
import com.netscape.certsrv.base.*;
import netscape.security.x509.*;
import netscape.security.extensions.*;
import netscape.security.util.ObjectIdentifier;
import java.security.cert.CertificateException;
import com.netscape.cmscore.util.*;


/**
 * 
 * @author stevep
 * @version $Revision
 */
public class OidLoaderSubsystem implements ISubsystem {

    private IConfigStore mConfig = null;
    public  static final String ID = "oidmap";
    private String mId = ID;

    private static final String PROP_OID = "oid";
    private static final String PROP_CLASS = "class";

    /**
     * 
     */
    private OidLoaderSubsystem() {
    }

    /**
     * Retrieves subsystem identifier.
     */
    public String getId() {
        return mId;
    }

    public void setId(String id) throws EBaseException {
        mId = id;
    }

    // singleton enforcement

    private static OidLoaderSubsystem mInstance = new OidLoaderSubsystem();

    public static OidLoaderSubsystem getInstance() {
        return mInstance;
    }
	
    private static final int CertType_data[] = { 2, 16, 840, 1, 113730, 1, 1 };

    /**
     * Identifies the particular public key used to sign the certificate.
     */
    public static final ObjectIdentifier CertType_Id = new
        ObjectIdentifier(CertType_data);

    private static final String[][] oidMapEntries = new String[][] {
            {NSCertTypeExtension.class.getName(),
                CertType_Id.toString(),
                NSCertTypeExtension.NAME},
            {CertificateRenewalWindowExtension.class.getName(),
                CertificateRenewalWindowExtension.ID.toString(),
                CertificateRenewalWindowExtension.NAME},
            {CertificateScopeOfUseExtension.class.getName(),
                CertificateScopeOfUseExtension.ID.toString(),
                CertificateScopeOfUseExtension.NAME},
            {DeltaCRLIndicatorExtension.class.getName(),
                DeltaCRLIndicatorExtension.OID,
                DeltaCRLIndicatorExtension.NAME},
            {HoldInstructionExtension.class.getName(),
                HoldInstructionExtension.OID,
                HoldInstructionExtension.NAME},
            {InvalidityDateExtension.class.getName(),
                InvalidityDateExtension.OID,
                InvalidityDateExtension.NAME},
            {IssuingDistributionPointExtension.class.getName(),
                IssuingDistributionPointExtension.OID,
                IssuingDistributionPointExtension.NAME},
            {FreshestCRLExtension.class.getName(),
                FreshestCRLExtension.OID,
                FreshestCRLExtension.NAME},
        };

    /**
     * Initializes this subsystem with the given 
     * configuration store.
     * It first initializes resident subsystems,
     * and it loads and initializes loadable
     * subsystem specified in the configuration
     * store.
     * <P>
     * Note that individual subsystem should be
     * initialized in a separated thread if
     * it has dependency on the initialization
     * of other subsystems.
     * <P>
     *
     * @param owner owner of this subsystem
     * @param config configuration store
     */
    public synchronized void init(ISubsystem owner, IConfigStore config)
        throws EBaseException {
        if (Debug.ON) {
            Debug.trace("OIDLoaderSubsystem started");
        }
        mConfig = config;

        Enumeration names = mConfig.getSubStoreNames();

        // load static (build-in) extensions

        for (int i = 0; i < oidMapEntries.length; i++) {
            try {
                OIDMap.addAttribute(oidMapEntries[i][0],
                    oidMapEntries[i][1],
                    oidMapEntries[i][2]);
            } catch (Exception e) {
            }
        }

        // load dynamic extensions

        while (names.hasMoreElements()) {
            String substorename = (String) names.nextElement();
            IConfigStore substore = mConfig.getSubStore(substorename);

            try {
                String oidname = substore.getString(PROP_OID);
                String classname = substore.getString(PROP_CLASS);

                OIDMap.addAttribute(classname,
                    oidname,
                    substorename);
            } catch (EPropertyNotFound e) {
                // Log error
            } catch (CertificateException e) {
                // log error
            }
        }
    }

    public void startup() throws EBaseException {
    }

    /**
     * Stops this system.
     */
    public synchronized void shutdown() {
    }

    /*
     * Returns the root configuration storage of this system.
     * <P>
     *
     * @return configuration store of this subsystem
     */
    public IConfigStore getConfigStore() {
        return mConfig;
    }

}