Esempio n. 1
0
ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es)
{
    WebKit::WebCryptoKeyFormat format;
    if (!Key::parseFormat(rawFormat, format, es))
        return ScriptPromise();

    if (!keyData) {
        es.throwTypeError("Invalid keyData argument");
        return ScriptPromise();
    }

    WebKit::WebCryptoKeyUsageMask keyUsages;
    if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es))
        return ScriptPromise();

    WebKit::WebCryptoAlgorithm algorithm;
    if (!normalizeAlgorithm(rawAlgorithm, ImportKey, algorithm, es))
        return ScriptPromise();

    const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->baseAddress());

    RefPtr<CryptoResult> result = CryptoResult::create();
    WebKit::Platform::current()->crypto()->importKey(format, keyDataBytes, keyData->byteLength(), algorithm, extractable, keyUsages, result->result());
    return result->promise();
}
Esempio n. 2
0
static bool parseAlgorithm(const Dictionary& raw, blink::WebCryptoOperation op, blink::WebCryptoAlgorithm& algorithm, CryptoResult* result)
{
    AlgorithmError error;
    bool success = normalizeAlgorithm(raw, op, algorithm, &error);
    if (!success)
        result->completeWithError(error.errorType, error.errorDetails);
    return success;
}
  AlgorithmName::AlgorithmName(const WideString& algorithm, bool cipherOnly)
    : m_normal(TextConvert::WideToNarrow(normalizeAlgorithm(algorithm)))
  {
    ASSERT( !algorithm.empty() );

    // We'd prefer to throw in the ctor, but its a limitation, not a feature!
    // Actually, we need to narmalize first (in case of throw), so maybe it is a feature.
    NarrowString cipher;
    getCipher(cipher);

    if(cipherOnly && m_normal != cipher)
      throw NoSuchAlgorithmException(m_normal + " not available");
  }
Esempio n. 4
0
ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es)
{
    WebKit::WebCryptoKeyUsageMask keyUsages;
    if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es))
        return ScriptPromise();

    WebKit::WebCryptoAlgorithm algorithm;
    if (!normalizeAlgorithm(rawAlgorithm, GenerateKey, algorithm, es))
        return ScriptPromise();

    RefPtr<CryptoResult> result = CryptoResult::create();
    WebKit::Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages, result->result());
    return result->promise();
}
WebCryptoAlgorithm normalizeCryptoAlgorithm(v8::Local<v8::Object> algorithmObject, WebCryptoOperation operation, int* exceptionCode, WebString* errorDetails, v8::Isolate* isolate)
{
    // FIXME: Avoid using NonThrowableExceptionState.
    NonThrowableExceptionState exceptionState;
    Dictionary algorithmDictionary(algorithmObject, isolate, exceptionState);
    if (!algorithmDictionary.isUndefinedOrNull() && !algorithmDictionary.isObject())
        return WebCryptoAlgorithm();
    WebCryptoAlgorithm algorithm;
    AlgorithmError error;
    AlgorithmIdentifier algorithmIdentifier;
    algorithmIdentifier.setDictionary(algorithmDictionary);
    if (!normalizeAlgorithm(algorithmIdentifier, operation, algorithm, &error)) {
        *exceptionCode = webCryptoErrorToExceptionCode(error.errorType);
        *errorDetails = error.errorDetails;
        return WebCryptoAlgorithm();
    }

    return algorithm;
}
 WideString AlgorithmName::normalizeAlgorithm(const WideString& name)
 {
   NarrowString narrow = TextConvert::WideToNarrow(name);
   narrow = normalizeAlgorithm(narrow);
   return TextConvert::NarrowToWide(narrow);
 }