Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Bug 1172785 - RTCCertificate implementation, r=rbarnes
Browse files Browse the repository at this point in the history
--HG--
extra : commitid : CBco7h85lO6
extra : rebase_source : 9cec281dd07e6d503a19a0ea57e5d4ceee98197c
  • Loading branch information
martinthomson committed Jul 6, 2015
1 parent a9fc4bf commit 93f1797
Show file tree
Hide file tree
Showing 8 changed files with 798 additions and 210 deletions.
1 change: 1 addition & 0 deletions config/external/nss/nss.def
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CERT_CacheOCSPResponseFromSideChannel
CERT_CertChainFromCert
CERT_CertificateRequestTemplate DATA
CERT_CertificateTemplate DATA
CERT_CertListFromCert
CERT_ChangeCertTrust
CERT_CheckCertUsage
CERT_CheckCertValidTimes
Expand Down
2 changes: 2 additions & 0 deletions dom/base/StructuredCloneTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ enum StructuredCloneTags {

SCTAG_DOM_NFC_NDEF,

SCTAG_DOM_RTC_CERTIFICATE,

SCTAG_DOM_MAX
};

Expand Down
28 changes: 28 additions & 0 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#ifdef MOZ_NFC
#include "mozilla/dom/MozNDEFRecord.h"
#endif // MOZ_NFC
#include "mozilla/dom/RTCCertificate.h"
#include "mozilla/dom/RTCCertificateBinding.h"
#include "mozilla/dom/StructuredClone.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "mozilla/ipc/BackgroundUtils.h"
Expand Down Expand Up @@ -2547,6 +2549,25 @@ NS_DOMReadStructuredClone(JSContext* cx,
#endif
}

if (tag == SCTAG_DOM_RTC_CERTIFICATE) {
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(cx));
if (!global) {
return nullptr;
}

// Prevent the return value from being trashed by a GC during ~nsRefPtr.
JS::Rooted<JSObject*> result(cx);
{
nsRefPtr<RTCCertificate> cert = new RTCCertificate(global);
if (!cert->ReadStructuredClone(reader)) {
result = nullptr;
} else {
result = cert->WrapObject(cx, nullptr);
}
}
return result;
}

// Don't know what this is. Bail.
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
return nullptr;
Expand All @@ -2571,6 +2592,13 @@ NS_DOMWriteStructuredClone(JSContext* cx,
key->WriteStructuredClone(writer);
}

// Handle WebRTC Certificate cloning
RTCCertificate* cert;
if (NS_SUCCEEDED(UNWRAP_OBJECT(RTCCertificate, obj, cert))) {
return JS_WriteUint32Pair(writer, SCTAG_DOM_RTC_CERTIFICATE, 0) &&
cert->WriteStructuredClone(writer);
}

if (xpc::IsReflector(obj)) {
nsCOMPtr<nsISupports> base = xpc::UnwrapReflectorToISupports(obj);
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(base);
Expand Down
14 changes: 10 additions & 4 deletions dom/crypto/WebCryptoCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,21 @@ ReadBuffer(JSStructuredCloneReader* aReader, CryptoBuffer& aBuffer)
}

inline bool
WriteBuffer(JSStructuredCloneWriter* aWriter, const CryptoBuffer& aBuffer)
WriteBuffer(JSStructuredCloneWriter* aWriter, const uint8_t* aBuffer, size_t aLength)
{
bool ret = JS_WriteUint32Pair(aWriter, aBuffer.Length(), 0);
if (ret && aBuffer.Length() > 0) {
ret = JS_WriteBytes(aWriter, aBuffer.Elements(), aBuffer.Length());
bool ret = JS_WriteUint32Pair(aWriter, aLength, 0);
if (ret && aLength > 0) {
ret = JS_WriteBytes(aWriter, aBuffer, aLength);
}
return ret;
}

inline bool
WriteBuffer(JSStructuredCloneWriter* aWriter, const CryptoBuffer& aBuffer)
{
return WriteBuffer(aWriter, aBuffer.Elements(), aBuffer.Length());
}

inline CK_MECHANISM_TYPE
MapAlgorithmNameToMechanism(const nsString& aName)
{
Expand Down
Loading

0 comments on commit 93f1797

Please sign in to comment.