Closed Bug 946348 Opened 11 years ago Closed 11 years ago

Refactor DtlsIdentity fingerprint functions

Categories

(Core :: WebRTC, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla29

People

(Reporter: mt, Assigned: mt)

References

()

Details

Attachments

(1 file, 6 obsolete files)

My review of the patch for bug 892148 highlighted an encapsulation issue. This is an easy fix.
Attachment #8343399 - Flags: review?(adam)
I realized that this is more than a straight refactor, but no sense in doing things twice when what you need is just lying around.
Comment on attachment 8343399 [details] [diff] [review] Refactoring DtlsIdentity interface; improving performance of call setup by an infinitesimal amount as a result. Review of attachment 8343399 [details] [diff] [review]: ----------------------------------------------------------------- r+, contingent on addressing the nits described below. ::: media/mtransport/dtlsidentity.cpp @@ +24,5 @@ > if (cert_) > CERT_DestroyCertificate(cert_); > } > > +const std::string DtlsIdentity::HASH_ALGORITHM = "sha-256"; s/HASH_ALGORITHM/DEFAULT_HASH_ALGORITHM/ @@ +218,5 @@ > + > +std::string DtlsIdentity::GetFormattedFingerprint(const std::string algorithm) { > + unsigned char digest[HASH_ALGORITHM_MAX_LENGTH]; > + size_t digest_length; > + Trailing WS @@ +224,5 @@ > + digest, > + sizeof(digest), > + &digest_length); > + if (NS_FAILED(res)) { > + MOZ_MTLOG(ML_ERROR, "Unable to compute " << algorithm Trailing WS @@ +225,5 @@ > + sizeof(digest), > + &digest_length); > + if (NS_FAILED(res)) { > + MOZ_MTLOG(ML_ERROR, "Unable to compute " << algorithm > + << " hash for identity: " << static_cast<uint32_t>(res)); nsresult is almost always hex formatted. I don't know of a good, universally available way to print it, but at a bare minimum, you'll want to do something like this: > #include <iomanip> > > ... > > << "nsresult = 0x" > << std::hex << std::uppercase > << static_cast<uint32_t>(res) > << std::nouppercase << std::dec); ::: media/mtransport/dtlsidentity.h @@ +32,5 @@ > CERTCertificate *cert() { return cert_; } > SECKEYPrivateKey *privkey() { return privkey_; } > > + std::string GetFormattedFingerprint(); > + std::string GetFormattedFingerprint(const std::string algorithm); There isn't any reason to copy the string in here; use a const reference. Also, it's not clear from the header that these functions do the same thing; consider collapsing them together: std::string GetFormattedFingerprint(const std::string &algorithm = DEFAULT_HASH_ALGORITHM); ::: media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp @@ +1177,5 @@ > /* > * Get DTLS key data > * > * @param[in] peerconnection - the peerconnection in use > * @param[out] digest_algp - the digest algorithm e.g. 'SHA-1' Given that sha-1 is now deprecated, let's change this example to "sha-256" (note the lowercasing, since that's what we appear to be returning). @@ +1204,5 @@ > return VCM_ERROR; > } > > + sstrncpy(digest_algp, fp.substr(0, spc).c_str(), max_digest_alg_len); > + sstrncpy(digestp, fp.c_str() + spc + 1, max_digest_len); This is a bit ungainly. I would suggest some means of getting these two different elements directly from the PC (e.g., "GetFingerprintAlgorithm()" and "GetFingerprintValue()") ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ +244,5 @@ > } > > // Get the DTLS identity > + mozilla::RefPtr<DtlsIdentity> const GetIdentity() const; > + std::string GetFingerprint() const; const std::string &GetFingerprint() const;
Attachment #8343399 - Flags: review?(adam) → review+
(In reply to Adam Roach [:abr] from comment #3) > nsresult is almost always hex formatted. I don't know of a good, universally > available way to print it, but at a bare minimum, you'll want to do > something like this: Puke. OK. > std::string GetFormattedFingerprint(const std::string &algorithm = > DEFAULT_HASH_ALGORITHM); That's what I wanted. > @@ +1204,5 @@ > > return VCM_ERROR; > > } > > > > + sstrncpy(digest_algp, fp.substr(0, spc).c_str(), max_digest_alg_len); > > + sstrncpy(digestp, fp.c_str() + spc + 1, max_digest_len); > > This is a bit ungainly. I would suggest some means of getting these two > different elements directly from the PC (e.g., "GetFingerprintAlgorithm()" > and "GetFingerprintValue()") If I'm going to fix anything, probably not that. I'd start with sipcc. Ungainly is requesting that values be split into component parts, but to insist on a very particular string format for those parts rather than use a sensible structure, like say std::string + size_t + uint8_t*. I guess I could start over, create a new "Fingerprint" class, move the string formatting there from DtlsIdentity, use that as a return value from PeerConnectionImpl, change everything that depended on it to use the class sensibly, including sipcc. That would be the right thing to do. Would that be what you are suggesting? It didn't seem like it would be worthwhile.
Comment on attachment 8344933 [details] [diff] [review] Refactoring DtlsIdentity interface; improving performance of call setup by an infinitesimal amount as a result. Adam, I'll let you decide how to proceed here. I've addressed the nits aside from the big one. I don't know if you want r? or checkin? at this point.
Attached patch Refactoring fingerprint handling (obsolete) — Splinter Review
Attachment #8349669 - Attachment is obsolete: true
Attached patch Refactoring fingerprint handling (obsolete) — Splinter Review
Attachment #8343399 - Attachment is obsolete: true
Attachment #8344933 - Attachment is obsolete: true
Comment on attachment 8349678 [details] [diff] [review] Refactoring fingerprint handling This should make Adam happier. VcmSIPCCBinding gets less complex. I am disappointed that this is a net global loss of efficiency, but...the net effect should be minimal, if not zero.
Attachment #8349678 - Flags: checkin?(adam)
Comment on attachment 8349678 [details] [diff] [review] Refactoring fingerprint handling BTW, you can just use the checkin-needed bug keyword when you need landing assistance. It's a bit easier to work with.
Attachment #8349678 - Flags: checkin?(adam) → checkin+
Attachment #8349678 - Attachment is obsolete: true
Attachment #8350185 - Attachment is obsolete: true
Attachment #8350188 - Attachment is obsolete: true
Keywords: checkin-needed
Adam, is this good to go?
Flags: needinfo?(adam)
Flags: needinfo?(adam)
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
Depends on: 989425
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: