75f5c2db254c0167a0e396254460de09b775d203trawick/* Licensed to the Apache Software Foundation (ASF) under one or more
75f5c2db254c0167a0e396254460de09b775d203trawick * contributor license agreements. See the NOTICE file distributed with
75f5c2db254c0167a0e396254460de09b775d203trawick * this work for additional information regarding copyright ownership.
75f5c2db254c0167a0e396254460de09b775d203trawick * The ASF licenses this file to You under the Apache License, Version 2.0
75f5c2db254c0167a0e396254460de09b775d203trawick * (the "License"); you may not use this file except in compliance with
75f5c2db254c0167a0e396254460de09b775d203trawick * the License. You may obtain a copy of the License at
75f5c2db254c0167a0e396254460de09b775d203trawick * Unless required by applicable law or agreed to in writing, software
75f5c2db254c0167a0e396254460de09b775d203trawick * distributed under the License is distributed on an "AS IS" BASIS,
75f5c2db254c0167a0e396254460de09b775d203trawick * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
75f5c2db254c0167a0e396254460de09b775d203trawick * See the License for the specific language governing permissions and
75f5c2db254c0167a0e396254460de09b775d203trawick * limitations under the License.
75f5c2db254c0167a0e396254460de09b775d203trawickstatic apr_status_t verify_signature(sct_fields_t *sctf,
75f5c2db254c0167a0e396254460de09b775d203trawick ap_assert(1 == EVP_VerifyUpdate(&ctx, sctf->signed_data,
75f5c2db254c0167a0e396254460de09b775d203trawick rc = EVP_VerifyFinal(&ctx, sctf->sig, sctf->siglen, pkey);
75f5c2db254c0167a0e396254460de09b775d203trawickapr_status_t sct_verify_signature(conn_rec *c, sct_fields_t *sctf,
75f5c2db254c0167a0e396254460de09b775d203trawick for (i = 0; i < nelts; i++) {
75f5c2db254c0167a0e396254460de09b775d203trawick if (!log_valid_for_received_sct(config_elts[i], sctf->time)) {
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick "out of trusted time interval");
75f5c2db254c0167a0e396254460de09b775d203trawick "verify_signature succeeded");
75f5c2db254c0167a0e396254460de09b775d203trawick /* no room for header */
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02768) "SCT size %" APR_SIZE_T_FMT " is too small",
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_deserialize_uint64(&cur, &len, &fields->timestamp);
75f5c2db254c0167a0e396254460de09b775d203trawick fields->time = apr_time_from_msec(fields->timestamp);
75f5c2db254c0167a0e396254460de09b775d203trawick /* XXX maybe do this only if log level is such that we'll
75f5c2db254c0167a0e396254460de09b775d203trawick * use it later?
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02769) "SCT size %" APR_SIZE_T_FMT " has no space "
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_deserialize_uint16(&cur, &len, &fields->extlen);
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02770) "SCT size %" APR_SIZE_T_FMT " has no "
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick "space for %hu bytes of extensions",
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02771) "SCT size %" APR_SIZE_T_FMT " has no space "
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick "for hash algorithm, signature algorithm, and "
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick "signature len",
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_deserialize_uint16(&cur, &len, &fields->siglen);
75f5c2db254c0167a0e396254460de09b775d203trawick /* If we have the server certificate, we can construct the
75f5c2db254c0167a0e396254460de09b775d203trawick * data over which the signature is computed.
75f5c2db254c0167a0e396254460de09b775d203trawick /* XXX Which part is signed? */
75f5c2db254c0167a0e396254460de09b775d203trawick /* See certificate-transparency/src/proto/serializer.cc,
75f5c2db254c0167a0e396254460de09b775d203trawick * method Serializer::SerializeV1CertSCTSignatureInput()
75f5c2db254c0167a0e396254460de09b775d203trawick + 2 + fields->extlen /* 16-bit length + extensions */
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_serialize_uint8(&mem, &avail, 0); /* version 1 */
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_serialize_uint8(&mem, &avail, 0); /* CERTIFICATE_TIMESTAMP */
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_serialize_uint64(&mem, &avail, fields->timestamp);
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_serialize_uint16(&mem, &avail, 0); /* X509_ENTRY */
75f5c2db254c0167a0e396254460de09b775d203trawick /* Get DER encoding of leaf certificate */
75f5c2db254c0167a0e396254460de09b775d203trawick /* get OpenSSL to allocate: */
75f5c2db254c0167a0e396254460de09b775d203trawick rv = ctutil_write_var16_bytes(&mem, &avail, fields->extensions,
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02773) "Failed to reconstruct signed data for "
75f5c2db254c0167a0e396254460de09b775d203trawick if (avail != 0) {
75f5c2db254c0167a0e396254460de09b775d203trawick /* Force invalid signature error: orig_mem[0] = orig_mem[0] + 1; */
75f5c2db254c0167a0e396254460de09b775d203trawick "SCT from %s: version %d timestamp %s hash alg %d sig alg %d",
75f5c2db254c0167a0e396254460de09b775d203trawick ap_log_data(APLOG_MARK, APLOG_DEBUG, s, "Signature",
75f5c2db254c0167a0e396254460de09b775d203trawick#endif /* httpd has ap_log_*data() */
75f5c2db254c0167a0e396254460de09b775d203trawick ap_assert(!(fields->signed_data && rv != APR_SUCCESS));
75f5c2db254c0167a0e396254460de09b775d203trawickapr_status_t sct_verify_timestamp(conn_rec *c, sct_fields_t *sctf)
a7452f0ad4045af1d42dce45cc25854e7bf3cac4trawick APLOGNO(02775) "Server sent SCT not yet valid (timestamp "