witchcraft_server/tls/client_certificate.rs
1// Copyright 2022 Palantir Technologies, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use rustls_pki_types::CertificateDer;
16
17/// A client's identity provided during the TLS handshake.
18///
19/// If client authentication is enabled and a client provides a certificate during the TLS handshake, this will be added
20/// to the extensions of each request made on that connection.
21#[derive(Clone)]
22pub struct ClientCertificate {
23 cert: CertificateDer<'static>,
24}
25
26// FIXME(sfackler) what accessors should we expose here? We probably want to avoid exposing `rustls` APIs directly.
27impl ClientCertificate {
28 pub(crate) fn new(cert: CertificateDer<'static>) -> Self {
29 ClientCertificate { cert }
30 }
31
32 pub(crate) fn cert(&self) -> &CertificateDer<'static> {
33 &self.cert
34 }
35}