Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show SHA256 fingerprints #1147

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/service/__init__.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,22 @@ Gio.TlsCertificate.new_for_paths = function (certPath, keyPath, commonName = nul

Object.defineProperties(Gio.TlsCertificate.prototype, {
/**
* Compute a SHA1 fingerprint of the certificate.
* Compute a SHA256 fingerprint of the certificate.
* See: https://gitlab.gnome.org/GNOME/glib/issues/1290
*
* @return {string} A SHA1 fingerprint of the certificate.
* @return {string} A SHA256 fingerprint of the certificate.
*/
'fingerprint': {
'sha256': {
value: function () {
if (!this.__fingerprint) {
const proc = new Gio.Subprocess({
argv: [Config.OPENSSL_PATH, 'x509', '-noout', '-fingerprint', '-sha1', '-inform', 'pem'],
argv: [Config.OPENSSL_PATH, 'x509', '-noout', '-fingerprint', '-sha256', '-inform', 'pem'],
flags: Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE,
});
proc.init(null);

const stdout = proc.communicate_utf8(this.certificate_pem, null)[1];
this.__fingerprint = /[a-zA-Z0-9:]{59}/.exec(stdout)[0];
this.__fingerprint = /[a-zA-Z0-9:]{95}/.exec(stdout)[0];
}

return this.__fingerprint;
Expand Down
6 changes: 3 additions & 3 deletions src/service/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ var Device = GObject.registerClass({

// If the device is connected use the certificate from the connection
} else if (this.connected) {
remoteFingerprint = this.channel.peer_certificate.fingerprint();
remoteFingerprint = this.channel.peer_certificate.sha256();

// Otherwise pull it out of the settings
} else if (this.paired) {
remoteFingerprint = Gio.TlsCertificate.new_from_pem(
this.settings.get_string('certificate-pem'),
-1
).fingerprint();
).sha256();
}

// FIXME: another ugly reach-around
Expand All @@ -186,7 +186,7 @@ var Device = GObject.registerClass({
lanBackend = this.service.manager.backends.get('lan');

if (lanBackend && lanBackend.certificate)
localFingerprint = lanBackend.certificate.fingerprint();
localFingerprint = lanBackend.certificate.sha256();

// TRANSLATORS: Label for TLS Certificate fingerprint
//
Expand Down