Skip to content

Commit

Permalink
8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneWeird committed Aug 21, 2019
1 parent 84f9448 commit f1f43d3
Show file tree
Hide file tree
Showing 38 changed files with 707 additions and 124 deletions.
2 changes: 1 addition & 1 deletion NetFrontBrowserNX_OSSCopyright.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OSS Copyright of NetFront Browser NX
Copyright (c) 2015-2018 ACCESS CO., LTD. All rights reserved.
Copyright (c) 2015-2019 ACCESS CO., LTD. All rights reserved.
Some files in this package were modified by ACCESS CO., LTD.
146 changes: 113 additions & 33 deletions WKC/WebCore/platform/WKC/CryptoKeyWKC.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 ACCESS CO., LTD. All rights reserved.
* Copyright (c) 2015-2019 ACCESS CO., LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -279,46 +279,126 @@ CryptoAlgorithmRegistry::platformRegisterAlgorithms(void)
void
CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParams& params, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback success, VoidCallback failureCallback, ExceptionCode& ec)
{
AES_KEY aes;
int ret = AES_set_encrypt_key(key.key().data(), key.key().size()*8, &aes);
if (ret<0) {
ec = ABORT_ERR;
failureCallback();
return;
EVP_CIPHER_CTX* ctx = nullptr;
const EVP_CIPHER* cipher = nullptr;

size_t buflen = ((data.second + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
Vector<uint8_t> ciphertext_buf(buflen);

unsigned char* ciphertext = ciphertext_buf.data();
int ciphertext_len = 0;

const unsigned char* plaintext = data.first;
int plaintext_len = data.second;

int len = 0;

ctx = EVP_CIPHER_CTX_new();
if (!ctx)
goto error;

switch (key.key().size() * 8) {
case 128:
cipher = EVP_aes_128_cbc();
break;
case 192:
cipher = EVP_aes_192_cbc();
break;
case 256:
cipher = EVP_aes_256_cbc();
break;
default:
goto error;
}
size_t buflen = data.second;
if (buflen < AES_BLOCK_SIZE)
buflen = AES_BLOCK_SIZE + 1;
Vector<uint8_t> out(buflen);
AES_cbc_encrypt(data.first, out.data(), data.second, &aes, (unsigned char *)params.iv.data(), AES_ENCRYPT);
out.shrink(data.second);
success(out);

if (1 != EVP_EncryptInit_ex(ctx, cipher, nullptr, key.key().data(), reinterpret_cast<const unsigned char *>(params.iv.data())))
goto error;

if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
goto error;

ciphertext_len += len;

if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
goto error;

ciphertext_len += len;

EVP_CIPHER_CTX_free(ctx);

ciphertext_buf.shrink(ciphertext_len);
success(ciphertext_buf);

return;

error:
if (ctx)
EVP_CIPHER_CTX_free(ctx);

ec = ABORT_ERR;
failureCallback();
}

void
CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcParams& params, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback success, VoidCallback failureCallback, ExceptionCode& ec)
{
AES_KEY aes;
int ret = AES_set_decrypt_key(key.key().data(), key.key().size()*8, &aes);
if (ret<0) {
ec = ABORT_ERR;
failureCallback();
return;
}
Vector<uint8_t> out(data.second);
AES_cbc_encrypt(data.first, out.data(), data.second, &aes, (unsigned char *)params.iv.data(), AES_DECRYPT);
EVP_CIPHER_CTX* ctx = nullptr;
const EVP_CIPHER* cipher = nullptr;

if (out.isEmpty()) {
ec = ABORT_ERR;
failureCallback();
return;
}
size_t destlen = ::strlen((char *)out.data());
if (destlen > AES_BLOCK_SIZE && !(destlen % AES_BLOCK_SIZE)) {
destlen -= AES_BLOCK_SIZE;
out.shrink(destlen);
Vector<uint8_t> plaintext_buf(data.second);

unsigned char* plaintext = plaintext_buf.data();
int plaintext_len = 0;

const unsigned char* ciphertext = data.first;
int ciphertext_len = data.second;

int len = 0;

ctx = EVP_CIPHER_CTX_new();
if (!ctx)
goto error;

switch (key.key().size() * 8) {
case 128:
cipher = EVP_aes_128_cbc();
break;
case 192:
cipher = EVP_aes_192_cbc();
break;
case 256:
cipher = EVP_aes_256_cbc();
break;
default:
goto error;
}
success(out);

if (1 != EVP_DecryptInit_ex(ctx, cipher, nullptr, key.key().data(), reinterpret_cast<const unsigned char *>(params.iv.data())))
goto error;

if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
goto error;

plaintext_len += len;

if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
goto error;

plaintext_len += len;

EVP_CIPHER_CTX_free(ctx);

plaintext_buf.shrink(plaintext_len);
success(plaintext_buf);

return;

error:
if (ctx)
EVP_CIPHER_CTX_free(ctx);

ec = ABORT_ERR;
failureCallback();
}

void
Expand Down
40 changes: 35 additions & 5 deletions WKC/WebCore/platform/WKC/SharedBufferWKC.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 Collabora Ltd.
* Copyright (c) 2010, 2015 ACCESS CO., LTD. All rights reserved.
* Copyright (c) 2010-2019 ACCESS CO., LTD. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -23,17 +23,47 @@
#include "CString.h"
#include "FileSystem.h"

#include "NotImplemented.h"
#include <wkc/wkcfilepeer.h>

#ifdef __WKC_IMPLICIT_INCLUDE_SYSSTAT
#include <sys/stat.h>
#endif

namespace WebCore {

RefPtr<SharedBuffer>
SharedBuffer::createFromReadingFile(const String& filePath)
{
notImplemented();
if (filePath.isEmpty())
return 0;
return 0;
return nullptr;

CString filename = fileSystemRepresentation(filePath);
void* fd = wkcFileFOpenPeer(WKC_FILEOPEN_USAGE_WEBCORE, filename.data(), "rb");
if (!fd)
return nullptr;

struct stat fileStat;
if (wkcFileFStatPeer(fd, &fileStat) == -1) {
wkcFileFClosePeer(fd);
return nullptr;
}

size_t bytesToRead = fileStat.st_size;
if (fileStat.st_size < 0 || bytesToRead != static_cast<unsigned long long>(fileStat.st_size)) {
wkcFileFClosePeer(fd);
return nullptr;
}

Vector<char> buffer(bytesToRead);

size_t totalBytesRead = 0;
ssize_t bytesRead;
while ((bytesRead = wkcFileFReadPeer(buffer.data() + totalBytesRead, 1, bytesToRead - totalBytesRead, fd)) > 0)
totalBytesRead += bytesRead;

wkcFileFClosePeer(fd);

return totalBytesRead == bytesToRead ? SharedBuffer::adoptVector(buffer) : nullptr;
}

} // namespace WebCore
Loading

0 comments on commit f1f43d3

Please sign in to comment.