@@ -101,11 +101,25 @@ var (
101
101
102
102
type TLSSubjectInfo struct {
103
103
CommonName string `json:"common_name"`
104
- Org string `json:"org" json:"organization"`
105
- OrgUnit string `json:"org_unit" json:"organizational_unit"`
106
- City string `json:"city" json:"locality"`
107
- State string `json:"state" json:"province"`
108
104
Country string `json:"country"`
105
+
106
+ // These fields have multiple names that they can be encoded as, so we use a different field to handle those.
107
+ Org string
108
+ OrgUnit string
109
+ City string
110
+ State string
111
+
112
+ // These fields are used to handle multiple json encodings for the actual field. For example, Org can be encoded in
113
+ // json as "org" or "organization". Which one is preferred in the case where both encodings are provided is
114
+ // arbitrary (undefined behavior).
115
+ OrgEncodedAsOrg * string `json:"org,omitempty"`
116
+ OrgEncodedAsOrganization * string `json:"organization,omitempty"`
117
+ OrgUnitEncodedAsOrgUnit * string `json:"org_unit,omitempty"`
118
+ OrgUnitEncodedAsOrganizationalUnit * string `json:"organizational_unit,omitempty"`
119
+ CityEncodedAsCity * string `json:"city,omitempty"`
120
+ CityEncodedAsLocality * string `json:"locality,omitempty"`
121
+ StateEncodedAsState * string `json:"state,omitempty" json:"province"`
122
+ StateEncodedAsProvince * string `json:"province,omitempty"`
109
123
}
110
124
111
125
type TLSFlags struct {
@@ -128,9 +142,27 @@ func parseOrCreateTLSSubjectInfo(jsonString string) (TLSSubjectInfo, error) {
128
142
return subjectInfo , errors .WithStackTrace (err )
129
143
}
130
144
}
145
+
146
+ // Reconcile multiple encoding name fields
147
+ subjectInfo .Org = getStringFromEncodingOrEmpty (subjectInfo .OrgEncodedAsOrg , subjectInfo .OrgEncodedAsOrganization )
148
+ subjectInfo .OrgUnit = getStringFromEncodingOrEmpty (subjectInfo .OrgUnitEncodedAsOrgUnit , subjectInfo .OrgUnitEncodedAsOrganizationalUnit )
149
+ subjectInfo .City = getStringFromEncodingOrEmpty (subjectInfo .CityEncodedAsCity , subjectInfo .CityEncodedAsLocality )
150
+ subjectInfo .State = getStringFromEncodingOrEmpty (subjectInfo .StateEncodedAsState , subjectInfo .StateEncodedAsProvince )
151
+
131
152
return subjectInfo , nil
132
153
}
133
154
155
+ // setStringFromEncoding will return the first non-empty string from the list of strings passed in, or empty string if
156
+ // they are all unset.
157
+ func getStringFromEncodingOrEmpty (encodings ... * string ) string {
158
+ for _ , encoding := range encodings {
159
+ if encoding != nil && * encoding != "" {
160
+ return * encoding
161
+ }
162
+ }
163
+ return ""
164
+ }
165
+
134
166
// parseTLSFlagsToPkixName takes the CLI args related to setting up the Distinguished Name identifier of the TLS
135
167
// certificate and converts them to the pkix.Name struct.
136
168
func parseTLSFlagsToPkixName (cliContext * cli.Context , tlsFlags TLSFlags ) (pkix.Name , error ) {
0 commit comments