|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2016 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package api |
| 18 | + |
| 19 | +import ( |
| 20 | + "time" |
| 21 | + |
| 22 | + "github.com/cloudflare/cfssl/csr" |
| 23 | + "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/tcert" |
| 24 | +) |
| 25 | + |
| 26 | +// RegistrationRequest for a new identity |
| 27 | +type RegistrationRequest struct { |
| 28 | + // Name is the unique name of the identity |
| 29 | + Name string `json:"id" help:"Unique name of the identity"` |
| 30 | + // Type of identity being registered (e.g. "peer, app, user") |
| 31 | + Type string `json:"type" help:"Type of identity being registered (e.g. 'peer, app, user')"` |
| 32 | + // Secret is an optional password. If not specified, |
| 33 | + // a random secret is generated. In both cases, the secret |
| 34 | + // is returned in the RegistrationResponse. |
| 35 | + Secret string `json:"secret,omitempty" help:"The enrollment secret for the identity being registered"` |
| 36 | + // MaxEnrollments is the maximum number of times the secret can |
| 37 | + // be reused to enroll. |
| 38 | + MaxEnrollments int `json:"max_enrollments,omitempty" def:"-1" help:"The maximum number of times the secret can be reused to enroll."` |
| 39 | + // is returned in the response. |
| 40 | + // The identity's affiliation. |
| 41 | + // For example, an affiliation of "org1.department1" associates the identity with "department1" in "org1". |
| 42 | + Affiliation string `json:"affiliation" help:"The identity's affiliation"` |
| 43 | + // Attributes associated with this identity |
| 44 | + Attributes []Attribute `json:"attrs,omitempty"` |
| 45 | + // CAName is the name of the CA to connect to |
| 46 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 47 | +} |
| 48 | + |
| 49 | +// RegistrationResponse is a registration response |
| 50 | +type RegistrationResponse struct { |
| 51 | + // The secret returned from a successful registration response |
| 52 | + Secret string `json:"secret"` |
| 53 | +} |
| 54 | + |
| 55 | +// EnrollmentRequest is a request to enroll an identity |
| 56 | +type EnrollmentRequest struct { |
| 57 | + // The identity name to enroll |
| 58 | + Name string `json:"name" skip:"true"` |
| 59 | + // The secret returned via Register |
| 60 | + Secret string `json:"secret,omitempty" skip:"true"` |
| 61 | + // Profile is the name of the signing profile to use in issuing the certificate |
| 62 | + Profile string `json:"profile,omitempty" help:"Name of the signing profile to use in issuing the certificate"` |
| 63 | + // Label is the label to use in HSM operations |
| 64 | + Label string `json:"label,omitempty" help:"Label to use in HSM operations"` |
| 65 | + // CSR is Certificate Signing Request info |
| 66 | + CSR *CSRInfo `json:"csr,omitempty" help:"Certificate Signing Request info"` |
| 67 | + // CAName is the name of the CA to connect to |
| 68 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 69 | +} |
| 70 | + |
| 71 | +// ReenrollmentRequest is a request to reenroll an identity. |
| 72 | +// This is useful to renew a certificate before it has expired. |
| 73 | +type ReenrollmentRequest struct { |
| 74 | + // Profile is the name of the signing profile to use in issuing the certificate |
| 75 | + Profile string `json:"profile,omitempty"` |
| 76 | + // Label is the label to use in HSM operations |
| 77 | + Label string `json:"label,omitempty"` |
| 78 | + // CSR is Certificate Signing Request info |
| 79 | + CSR *CSRInfo `json:"csr,omitempty"` |
| 80 | + // CAName is the name of the CA to connect to |
| 81 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 82 | +} |
| 83 | + |
| 84 | +// RevocationRequest is a revocation request for a single certificate or all certificates |
| 85 | +// associated with an identity. |
| 86 | +// To revoke a single certificate, both the Serial and AKI fields must be set; |
| 87 | +// otherwise, to revoke all certificates and the identity associated with an enrollment ID, |
| 88 | +// the Name field must be set to an existing enrollment ID. |
| 89 | +// A RevocationRequest can only be performed by a user with the "hf.Revoker" attribute. |
| 90 | +type RevocationRequest struct { |
| 91 | + // Name of the identity whose certificates should be revoked |
| 92 | + // If this field is omitted, then Serial and AKI must be specified. |
| 93 | + Name string `json:"id,omitempty" opt:"e" help:"Identity whose certificates should be revoked"` |
| 94 | + // Serial number of the certificate to be revoked |
| 95 | + // If this is omitted, then Name must be specified |
| 96 | + Serial string `json:"serial,omitempty" opt:"s" help:"Serial number of the certificate to be revoked"` |
| 97 | + // AKI (Authority Key Identifier) of the certificate to be revoked |
| 98 | + AKI string `json:"aki,omitempty" opt:"a" help:"AKI (Authority Key Identifier) of the certificate to be revoked"` |
| 99 | + // Reason is the reason for revocation. See https://godoc.org/golang.org/x/crypto/ocsp for |
| 100 | + // valid values. The default value is 0 (ocsp.Unspecified). |
| 101 | + Reason string `json:"reason,omitempty" opt:"r" help:"Reason for revocation"` |
| 102 | + // CAName is the name of the CA to connect to |
| 103 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 104 | +} |
| 105 | + |
| 106 | +// GetTCertBatchRequest is input provided to identity.GetTCertBatch |
| 107 | +type GetTCertBatchRequest struct { |
| 108 | + // Number of TCerts in the batch. |
| 109 | + Count int `json:"count"` |
| 110 | + // The attribute names whose names and values are to be sealed in the issued TCerts. |
| 111 | + AttrNames []string `json:"attr_names,omitempty"` |
| 112 | + // EncryptAttrs denotes whether to encrypt attribute values or not. |
| 113 | + // When set to true, each issued TCert in the batch will contain encrypted attribute values. |
| 114 | + EncryptAttrs bool `json:"encrypt_attrs,omitempty"` |
| 115 | + // Certificate Validity Period. If specified, the value used |
| 116 | + // is the minimum of this value and the configured validity period |
| 117 | + // of the TCert manager. |
| 118 | + ValidityPeriod time.Duration `json:"validity_period,omitempty"` |
| 119 | + // The pre-key to be used for key derivation. |
| 120 | + PreKey string `json:"prekey"` |
| 121 | + // DisableKeyDerivation if true disables key derivation so that a TCert is not |
| 122 | + // cryptographically related to an ECert. This may be necessary when using an |
| 123 | + // HSM which does not support the TCert's key derivation function. |
| 124 | + DisableKeyDerivation bool `json:"disable_kdf,omitempty"` |
| 125 | + // CAName is the name of the CA to connect to |
| 126 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 127 | +} |
| 128 | + |
| 129 | +// GetTCertBatchResponse is the return value of identity.GetTCertBatch |
| 130 | +type GetTCertBatchResponse struct { |
| 131 | + tcert.GetBatchResponse |
| 132 | +} |
| 133 | + |
| 134 | +// GetCAInfoRequest is request to get generic CA information |
| 135 | +type GetCAInfoRequest struct { |
| 136 | + CAName string `json:"caname,omitempty" skip:"true"` |
| 137 | +} |
| 138 | + |
| 139 | +// CSRInfo is Certificate Signing Request information |
| 140 | +type CSRInfo struct { |
| 141 | + CN string `json:"CN"` |
| 142 | + Names []csr.Name `json:"names,omitempty"` |
| 143 | + Hosts []string `json:"hosts,omitempty"` |
| 144 | + KeyRequest *csr.BasicKeyRequest `json:"key,omitempty"` |
| 145 | + CA *csr.CAConfig `json:"ca,omitempty"` |
| 146 | + SerialNumber string `json:"serial_number,omitempty"` |
| 147 | +} |
| 148 | + |
| 149 | +// Attribute is a name and value pair |
| 150 | +type Attribute struct { |
| 151 | + Name string `json:"name"` |
| 152 | + Value string `json:"value"` |
| 153 | +} |
0 commit comments