/
CMCUserSignedSubjectNameConstraint.java
128 lines (115 loc) · 4.85 KB
/
CMCUserSignedSubjectNameConstraint.java
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
// --- 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) 2013 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cms.profile.constraint;
import java.util.Locale;
import org.dogtagpki.server.authentication.AuthManager;
import org.mozilla.jss.netscape.security.x509.CertificateSubjectName;
import org.mozilla.jss.netscape.security.x509.X500Name;
import org.mozilla.jss.netscape.security.x509.X509CertInfo;
import com.netscape.certsrv.profile.ERejectException;
import com.netscape.cms.profile.common.EnrollProfile;
import com.netscape.cms.profile.def.CMCUserSignedSubjectNameDefault;
import com.netscape.cms.profile.def.PolicyDefault;
import com.netscape.cmscore.apps.CMS;
import com.netscape.cmscore.request.Request;
/**
* This class implements the user subject name constraint for user-signed cmc requests.
* It makes sure the signing cert's subjectDN and the rsulting cert match
*
* @author cfu
* @version $Revision$, $Date$
*/
public class CMCUserSignedSubjectNameConstraint extends EnrollConstraint {
public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CMCUserSignedSubjectNameConstraint.class);
public CMCUserSignedSubjectNameConstraint() {
}
/**
* Validates the request. The request is not modified
* during the validation. User encoded subject name
* is copied into the certificate template.
*/
@Override
public void validate(Request request, X509CertInfo info)
throws ERejectException {
String method = "CMCUserSignedSubjectNameConstraint: ";
String msg = "";
logger.debug(method + "validate start");
CertificateSubjectName infoCertSN = null;
CertificateSubjectName authTokenCertSN = null;
try {
infoCertSN = (CertificateSubjectName) info.get(X509CertInfo.SUBJECT);
if (infoCertSN == null) {
msg = method + "infoCertSN null";
logger.error(msg);
throw new Exception(msg);
}
logger.debug(method + "validate user subject=" + infoCertSN);
String certSerial = request.getExtDataInString(AuthManager.CRED_CMC_SIGNING_CERT);
if (certSerial == null) {
msg = method + "certSerial null";
logger.error(msg);
throw new Exception(msg);
}
authTokenCertSN =
EnrollProfile.getCMCSigningCertSNfromCertSerial(certSerial);
if (authTokenCertSN == null) {
msg = method + "authTokenCertSN null";
logger.error(msg);
throw new Exception(msg);
}
X500Name infoCertName = (X500Name) infoCertSN.get(CertificateSubjectName.DN_NAME);
if (infoCertName == null) {
msg = method + "infoCertName null";
logger.error(msg);
throw new Exception(msg);
}
X500Name authTokenCertName = (X500Name) authTokenCertSN.get(CertificateSubjectName.DN_NAME);
if (authTokenCertName == null) {
msg = method + "authTokenCertName null";
logger.error(msg);
throw new Exception(msg);
}
if (infoCertName.equals(authTokenCertName)) {
logger.debug(method + "names match");
} else {
msg = method + "names do not match";
logger.error(msg);
throw new Exception(msg);
}
} catch (Exception e) {
throw new ERejectException(
CMS.getUserMessage(getLocale(request),
"CMS_PROFILE_SUBJECT_NAME_NOT_MATCHED") + e);
}
}
@Override
public String getText(Locale locale) {
return CMS.getUserMessage(locale,
"CMS_PROFILE_CONSTRAINT_CMC_USER_SIGNED_SUBJECT_NAME_TEXT");
}
@Override
public boolean isApplicable(PolicyDefault def) {
String method = "CMCUserSignedSubjectNameConstraint: isApplicable: ";
if (def instanceof CMCUserSignedSubjectNameDefault) {
logger.debug(method + "true");
return true;
}
logger.debug(method + "false");
return false;
}
}