# Copyright 2021 - 2021 PeopleWare n.v.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

type: object
required:
  - kty
  - alg
  - kid
properties:
  kid:
    type: string
    minLength: 1
    description: >-
      The `kid` (key ID) parameter is used to match a specific key. This is used, for instance, to choose among a set of
      keys within a JWK Set during key rollover.


      The structure of the `kid` value is unspecified. The `kid` value is a case-sensitive string.


      When `kid` values are used within a JWK Set, different keys within the JWK Set **should** use distinct `kid`
      values. (One example in which different keys might use the same `kid` value is if they have different `kty` (key
      type) values but are considered to be equivalent alternatives by the application using them.)


      When used with JWS or JWE, the `kid` value is used to match a JWS or JWE `kid` Header Parameter value.


      Although the property is optional in [RFC 7517 Section 4.5](https://tools.ietf.org/html/rfc7517#section-4.5), it
      is required in this spec, because it is necessary to be able to verify the signature on Bearer Access Tokens
      received from a Secure Token Service: the resource service needs to be able to identify which JWK in the set was
      used to sign the Bearer Access Token.


      See [RFC 7517 Section 4.5](https://tools.ietf.org/html/rfc7517#section-4.5).
    example: 72bd9328-3e3e-46da-93da-bff6a66d275ds
  kty:
    type: string
    description: >-
      The `kty` (key type) parameter identifies the cryptographic algorithm family used with the key, such as `RSA` or
      `EC`.  `kty` values should either be registered in the IANA "JSON Web Key Types" registry established by
      [JWA](https://tools.ietf.org/html/rfc7518) or be a value that contains a Collision- Resistant Name.  The `kty`
      value is a case-sensitive string.


      A list of defined `kty` values can be found in the IANA "JSON Web Key Types" registry established by
      [JWA](https://tools.ietf.org/html/rfc7518); the initial contents of this registry are the values defined in
      [Section 6.1 of JWA](https://tools.ietf.org/html/rfc7518#section-6.1).


      The key type definitions include specification of the members to be used for those key types.  Members used with
      specific `kty` values can be found in the IANA "JSON Web Key Parameters" registry established by [Section 8.1 of
      RFC 7517](https://tools.ietf.org/html/rfc7517#section-8.1).


      See [RFC 7517 Section 4.1](https://tools.ietf.org/html/rfc7517#section-4.1).
    example: RSA
  alg:
    type: string
    enum:
      - HS256
      - HS384
      - HS512
      - RS256
      - RS384
      - RS512
      - ES256
      - ES384
      - ES512
      - PS256
      - PS384
      - PS512
    description: >-
      The `alg` (algorithm) parameter identifies the algorithm intended for use with the key.


      The values used should either be registered in the IANA "JSON Web Signature and Encryption Algorithms" registry
      established by [JWA](https://tools.ietf.org/html/rfc7518) or be a value that contains a Collision-Resistant Name.
      The `alg` value is a case-sensitive ASCII string.


      This specification only supports the values initially registered in [JWA Section
      3.1](https://tools.ietf.org/html/rfc7518#section-3.1). Although the property is optional in [RFC 7517 Section
      4.4](https://tools.ietf.org/html/rfc7517#section-4.4), it is required in this spec, because it is necessary to be
      able to verify the signature on Bearer Access Tokens received from a Secure Token Service whose implementation is
      unknown, and might change.


      See [RFC 7517 Section 4.4](https://tools.ietf.org/html/rfc7517#section-4.4).
    example: RS256
  use:
    type: string
    enum:
      - sig
      - enc
    description: >-
      The `use` (public key use) parameter identifies the intended use of the public key. The `use` parameter is
      employed to indicate whether a public key is used for encrypting data or verifying the signature on data.


      Values defined by this specification are:

      -  `sig` (signature)

      -  `enc` (encryption)


      Use of the `use` member is _optional_, unless the application requires its presence.


      When a key is used to wrap another key and a public key use designation for the first key is desired, the `enc`
      (encryption) key use value is used, since key wrapping is a kind of encryption. The `enc` value is also to be used
      for public keys used for key agreement operations.


      The `use` and `key_ops` JWK members **should not** be used together; however, if both are used, the information
      they convey **must** be consistent. Applications should specify which of these members they use, if either is to
      be used by the application.


      For validation of Bearer Access Tokens, the value of `use` must be `sig`. Note that most, if not all, Secure Token
      Services currently use the `use` key, with value `sig`.


      See [RFC 7517 Section 4.2](https://tools.ietf.org/html/rfc7517#section-4.2).
    example: sig
  key_ops:
    type: array
    items:
      type: string
      enum:
        - sign
        - verify
        - encrypt
        - decrypt
        - wrapKey
        - unwrapKey
        - deriveKey
        - deriveBits
      minItems: 1
      uniqueItems: true
    description: >-
      The `key_ops` (key operations) parameter identifies the operation(s) for which the key is intended to be used. The
      `key_ops` parameter is intended for use cases in which public, private, or symmetric keys may be present.

      Its value is an array of key operation values. Values defined by this specification are:

      -  `sign` (compute digital signature or MAC)

      -  `verify` (verify digital signature or MAC)

      -  `encrypt` (encrypt content)

      -  `decrypt` (decrypt content and validate decryption, if applicable)

      -  `wrapKey` (encrypt key)

      -  `unwrapKey` (decrypt key and validate decryption, if applicable)

      -  `deriveKey` (derive key)

      -  `deriveBits` (derive bits not to be used as a key)


      (Note that the `key_ops` values intentionally match the `KeyUsage` values defined in the [Web Cryptography
      API](https://www.w3.org/TR/WebCryptoAPI/) specification.)


      The key operation values are case-sensitive strings. Duplicate key operation values **must not** be present in the
      array. Use of the `key_ops` member is _optional_, unless the application requires its presence.


      Multiple unrelated key operations **should not** be specified for a key because of the potential vulnerabilities
      associated with using the same key with multiple algorithms. Thus, the combinations `sign` with `verify`,
      `encrypt` with `decrypt`, and `wrapKey` with `unwrapKey` are permitted, but other combinations **should not** be
      used.


      The `use` and `key_ops` JWK members **should not** be used together; however, if both are used, the information
      they convey **must** be consistent. Applications should specify which of these members they use, if either is to
      be used by the application.

      For validation of Bearer Access Tokens, the value of `key_ops` must contain `verify`.


      See [RFC 7517 Section 4.3](https://tools.ietf.org/html/rfc7517#section-4.3).
    example: [verify, sign]
  x5u:
    type: string
    format: uri
    description: >-
      The `x5u` (X.509 URL) parameter is a [URI](https://tools.ietf.org/html/rfc3986) that refers to a resource for an
      [X.509 public key certificate or certificate chain](https://tools.ietf.org/html/rfc5280). The identified resource
      **must** provide a representation of the certificate or certificate chain that conforms to [RFC
      5280](https://tools.ietf.org/html/rfc5280) in PEM-encoded form, with each certificate delimited as specified in
      [Section 6.1 of RFC 4945](https://tools.ietf.org/html/rfc4945#section-6.1). The key in the first certificate
      **must** match the public key represented by other members of the JWK. The protocol used to acquire the resource
      **must** provide integrity protection; an HTTP GET request to retrieve the certificate **must** use TLS [RFC
      5246](https://tools.ietf.org/html/rfc5246) [RFC 2818](https://tools.ietf.org/html/rfc2818); the identity of the
      server **must** be validated, as per [Section 6 of RFC 6125](https://tools.ietf.org/html/rfc6125#section-6).


      Use of this member is _optional_.


      While there is no requirement that optional JWK members providing key usage, algorithm, or other information be
      present when the `x5u` member is used, doing so may improve interoperability for applications that do not handle
      PKIX certificates [RFC 5280](https://tools.ietf.org/html/rfc5280). If other members are present, the contents of
      those members **must** be semantically consistent with the related fields in the first certificate. For instance,
      if the `use` member is present, then it **must** correspond to the usage that is specified in the certificate,
      when it includes this information. Similarly, if the `alg` member is present, it **must** correspond to the
      algorithm specified in the certificate.


      See [RFC 7517 Section 4.6](https://tools.ietf.org/html/rfc7517#section-4.6).
    example: https://example.com/certificates/key.pem
  x5c:
    type: array
    items:
      type: string
      format: base64
      minItems: 1
      uniqueItems: true
    description: >-
      The `x5c` (X.509 certificate chain) parameter contains a chain of one or more PKIX certificates [RFC
      5280](https://tools.ietf.org/html/rfc5280). The certificate chain is represented as a JSON array of certificate
      value strings. Each string in the array is a base64-encoded ([Section 4 of RFC
      4648](https://tools.ietf.org/html/rfc4648#section-4) — not base64url-encoded) DER _ITU.X690.1994_ PKIX certificate
      value. The PKIX certificate containing the key value **must** be the first certificate. This **may** be followed
      by additional certificates, with each subsequent certificate being the one used to certify the previous one. The
      key in the first certificate **must** match the public key represented by other members of the JWK.


      Use of this member is _optional_.


      While there is no requirement that optional JWK members providing key usage, algorithm, or other information be
      present when the `x5c` member is used, doing so may improve interoperability for applications that do not handle
      PKIX certificates [RFC 5280](https://tools.ietf.org/html/rfc5280). If other members are present, the contents of
      those members **must** be semantically consistent with the related fields in the first certificate. For instance,
      if the `use` member is present, then it **must** correspond to the usage that is specified in the certificate,
      when it includes this information. Similarly, if the `alg` member is present, it **must** correspond to the
      algorithm specified in the certificate.


      See [RFC 7517 Section 4.7](https://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887b9b51d80872cc3957b3dfe47d9904c56fa1aaaa5db32c
  x5t:
    type: string
    format: base64url
    description: >-
      The `x5t` (X.509 certificate SHA-1 thumbprint) parameter is a base64url-encoded SHA-1 thumbprint (a.k.a. digest)
      of the DER encoding of an X.509 certificate (See [RFC5280](https://tools.ietf.org/html/rfc5280)). Note that
      certificate thumbprints are also sometimes known as certificate fingerprints. The key in the certificate **must**
      match the public key represented by other members of the JWK.


      Use of this member is _optional_.


      While there is no requirement that optional JWK members providing key usage, algorithm, or other information be
      present when the `x5t` member is used, doing so may improve interoperability for applications that do not handle
      PKIX certificates (See [RFC 5280](https://tools.ietf.org/html/rfc5280)). If other members are present, the
      contents of those members **must** be semantically consistent with the related fields in the first certificate.
      For instance, if the `use` member is present, then it **must** correspond to the usage that is specified in the
      certificate, when it includes this information. Similarly, if the `alg` member is present, it **must** correspond
      to the algorithm specified in the certificate.


      In practice, if a thumbprint is given, it is either as SHA-1 in `x5t`, or as SHA-256 in `x5t#S256`, and then
      usually also used as `kid`.


      See [RFC 7517 Section 4.8](https://tools.ietf.org/html/rfc7517#section-4.8).
    example: NjVBRjY5MDlCMUIwNzU4RTA2QzZFMDQ4QzQ2MDAyQjVDNjk1RTM2Qg
  x5t#S256:
    type: string
    format: base64url
    description: >-
      The `x5t#S256` (X.509 certificate SHA-256 thumbprint) parameter is a base64url-encoded SHA-256 thumbprint (a.k.a.
      digest) of the DER encoding of an X.509 certificate (See [RFC 5280](https://tools.ietf.org/html/rfc5280)). Note
      that certificate thumbprints are also sometimes known as certificate fingerprints.The key in the certificate
      **must** match the public key represented by other members of the JWK.


      Use of this member is _optional_.


      While there is no requirement that optional JWK members providing key usage, algorithm, or other information be
      present when the `x5t#S256` member is used, doing so may improve interoperability for applications that do not
      handle PKIX certificates (See [RFC 5280](https://tools.ietf.org/html/rfc5280)). If other members are present, the
      contents of those members **must** be semantically consistent with the related fields in the first certificate.
      For instance, if the `use` member is present, then it **must** correspond to the usage that is specified in the
      certificate, when it includes this information. Similarly, if the `alg` member is present, it **must** correspond
      to the algorithm specified in the certificate.


      In practice, if a thumbprint is given, it is either as SHA-1 in `x5t`, or as SHA-256 in `x5t#S256`, and then
      usually also used as `kid`.


      See [RFC 7517 Section 4.9](https://tools.ietf.org/html/rfc7517#section-4.9).
    example: 557ee867372bdcf7887b9b51d80872cc3957b3dfe47d9904c56fa1aaaa5db32c
