/* * Copyright 2004 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Handling of certificates and keypairs for SSLStreamAdapter's peer mode. #include"rtc_base/ssl_identity.h"
namespace { // Read `n` bytes from ASN1 number string at *`pp` and return the numeric value. // Update *`pp` and *`np` to reflect number of read bytes. // TODO(bugs.webrtc.org/9860) - Remove this code. inlineint ASN1ReadInt(constunsignedchar** pp, size_t* np, size_t n) { constunsignedchar* p = *pp; int x = 0; for (size_t i = 0; i < n; i++) {
x = 10 * x + p[i] - '0';
}
*pp = p + n;
*np = *np - n; return x;
}
} // namespace
// TODO(bugs.webrtc.org/9860) - Remove this code.
int64_t ASN1TimeToSec(constunsignedchar* s, size_t length, bool long_format) {
size_t bytes_left = length; // Make sure the string ends with Z. Doing it here protects the strspn call // from running off the end of the string in Z's absense. if (length == 0 || s[length - 1] != 'Z') { return -1;
} // Make sure we only have ASCII digits so that we don't need to clutter the // code below and ASN1ReadInt with error checking.
size_t n = strspn(reinterpret_cast<constchar*>(s), "0123456789"); if (n + 1 != length) { return -1;
} // Read out ASN1 year, in either 2-char "UTCTIME" or 4-char "GENERALIZEDTIME" // format. Both format use UTC in this context. int year = 0; if (long_format) { // ASN1 format: yyyymmddhh[mm[ss[.fff]]]Z where the Z is literal, but // RFC 5280 requires us to only support exactly yyyymmddhhmmssZ. if (bytes_left < 11) { return -1;
}
year = ASN1ReadInt(&s, &bytes_left, 4);
year -= 1900;
} else { // ASN1 format: yymmddhhmm[ss]Z where the Z is literal, but RFC 5280 // requires us to only support exactly yymmddhhmmssZ. if (bytes_left < 9) { return -1;
}
year = ASN1ReadInt(&s, &bytes_left, 2); // Per RFC 5280 4.1.2.5.1 if (year < 50) {
year += 100;
}
}
// Read out remaining ASN1 time data and store it in `tm` in documented // std::tm format.
tm tm;
tm.tm_year = year;
tm.tm_mon = ASN1ReadInt(&s, &bytes_left, 2) - 1;
tm.tm_mday = ASN1ReadInt(&s, &bytes_left, 2);
tm.tm_hour = ASN1ReadInt(&s, &bytes_left, 2);
tm.tm_min = ASN1ReadInt(&s, &bytes_left, 2);
tm.tm_sec = ASN1ReadInt(&s, &bytes_left, 2);
// Now just Z should remain. Its existence was asserted above. if (bytes_left != 1) { return -1;
} return TmToSeconds(tm);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.