Skip to content

Commit

Permalink
Merge pull request #118 from poetaster/master
Browse files Browse the repository at this point in the history
Added https://github.com/Scarrough 's changes:
- Using openssl 1.1.x
Added @attah change:
- Move to WebView. This last we can make backwards compatible in future. For now, openrepos versions are still available for older versions < SFOS 4.x
  • Loading branch information
poetaster authored Mar 24, 2022
2 parents 22787ba + cc8528b commit fa8b33c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 37 deletions.
4 changes: 3 additions & 1 deletion hutspot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ HEADERS += \

INCLUDEPATH += src/qmdnsengine

QMAKE_LFLAGS += -lssl -lcrypto
#QMAKE_LFLAGS += -lssl -lcrypto

PKGCONFIG += openssl

CONFIG += console
21 changes: 3 additions & 18 deletions qml/components/WebAuth.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
//import QtWebKit.experimental 1.0
import Sailfish.WebView 1.0
import Sailfish.WebEngine 1.0

Page {
id: webAuth
Expand All @@ -26,7 +27,7 @@ Page {
}
}*/

SilicaWebView {
WebView {
id: webView

y: pHeader.height + Theme.paddingLarge
Expand All @@ -36,22 +37,6 @@ Page {
//experimental.preferences.developerExtrasEnabled: true
//experimental.preferences.navigatorQtObjectEnabled: true

Component.onCompleted: {
webAuth.scale = scale
}

// copied from webcat to get scaling of Spotify authentication html
// usable on phone screen
property variant devicePixelRatio: {//1.5
if (Screen.width <= 540) return 1.5;
else if (Screen.width > 540 && Screen.width <= 768) return 2.0;
else if (Screen.width > 768) return 3.0;
}
experimental.customLayoutWidth: width / devicePixelRatio
experimental.deviceWidth: width / devicePixelRatio
experimental.overview: true
experimental.userScripts: [
Qt.resolvedUrl("DevicePixelRatioHack.js")
]
}
}
8 changes: 4 additions & 4 deletions rpm/hutspot.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Name: hutspot
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Spotify controller for SailfishOS
Version: 0.2
Version: 0.3
Release: 1
Group: Qt/Qt
License: LICENSE
URL: http://example.org/
Group: Applications/Multimedia
License: MIT
URL: https://github.com/wdehoog/playspot
Source0: %{name}-%{version}.tar.bz2
Source100: hutspot.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
Expand Down
2 changes: 1 addition & 1 deletion rpm/hutspot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: hutspot
Summary: Spotify controller for SailfishOS
Version: 0.2
Version: 0.3
Group: Applications/Multimedia
URL: https://github.com/wdehoog/playspot
License: MIT
Expand Down
48 changes: 35 additions & 13 deletions src/connect/spconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/dh.h>
#include <openssl/modes.h>

#include <QCryptographicHash>
#include <QDebug>
Expand All @@ -28,24 +30,26 @@ void read_blob_bytes(QByteArray &blob, unsigned int * pos, QByteArray &data);

SPConnect::SPConnect(QObject *parent) : QObject(parent) {
mdnsService = nullptr;
const BIGNUM * pub_key=BN_new();

// setup dh keys
dh = get_dh();
// Librespot uses 95 byte keys
if(1 != DH_set_length(dh, 760)) {
qDebug() << "Failed to set length of private key";
return;
}
if(1 != DH_generate_key(dh)) {
qDebug() << "Failed to generate DH key pair";
return;
}

// Librespot uses 95 byte keys, openssl generated a 96 byte one
// so reduce by one byte
BN_rshift(dh->priv_key, dh->priv_key, 8);

// generate public key
powm(dh->g, dh->priv_key, dh->p, dh->pub_key);

int publicKeyLength = BN_num_bytes(dh->pub_key);
// BN_rshift(dh->priv_key, dh->priv_key, 8);
int publicKeyLength = BN_num_bytes(pub_key);
unsigned char * publicKeyBytes = (unsigned char *)malloc(publicKeyLength);
BN_bn2bin(dh->pub_key, publicKeyBytes);
BN_bn2bin(pub_key, publicKeyBytes);
QByteArray publicKey = QByteArray((const char*)publicKeyBytes, publicKeyLength);
publicKey64 = publicKey.toBase64();
//qDebug() << "publicKey: " << publicKey64;
Expand Down Expand Up @@ -135,9 +139,21 @@ QString SPConnect::createBlobToSend(QString deviceName, QString clientKey) {
// create shared_key
BIGNUM * clientKeyBN;
BIGNUM * sharedKeyBN = BN_new();
const BIGNUM * priv_key;
const BIGNUM * pub_key;
const BIGNUM * p;
BIGNUM * priv_keyd = BN_new();
BIGNUM * pub_keyd = BN_new();
BIGNUM * pd = BN_new();

DH_get0_pqg(dh, &p, NULL, NULL);
DH_get0_key(dh, &pub_key, &priv_key);
priv_keyd = BN_dup(priv_key);
pub_keyd = BN_dup(pub_key);
pd = BN_dup(p);
QByteArray decClientKey = QByteArray::fromBase64(clientKey.toUtf8());
clientKeyBN = BN_bin2bn((unsigned char *)decClientKey.data(), decClientKey.length(), nullptr);
powm(clientKeyBN, dh->priv_key, dh->p, sharedKeyBN);
powm(clientKeyBN, priv_keyd, pd, sharedKeyBN);
unsigned char * sharedKeyBytes = (unsigned char *)malloc(BN_num_bytes(sharedKeyBN));
BN_bn2bin(sharedKeyBN, sharedKeyBytes);
QByteArray sharedKey = QByteArray((const char*)sharedKeyBytes, BN_num_bytes(sharedKeyBN));
Expand Down Expand Up @@ -170,13 +186,14 @@ QString SPConnect::createBlobToSend(QString deviceName, QString clientKey) {
memset(ecount,0,sizeof(ecount));
len = encrypted_blob64.length();
unsigned char * encrypted_part = new unsigned char[len];
AES_ctr128_encrypt((const unsigned char *)encrypted_blob64.data(),
CRYPTO_ctr128_encrypt((const unsigned char *)encrypted_blob64.data(),
encrypted_part,
len,
&aes_key,
iv,
ecount,
&num);
&num,
(block128_f)AES_encrypt);
QByteArray encrypted_blob_part = QByteArray((const char*)encrypted_part, len);
//qDebug() << " encrypted_blob_part: " << encrypted_blob_part.toBase64();

Expand Down Expand Up @@ -290,11 +307,16 @@ DH * get_dh() {
0x02,
};
DH *dh;
BIGNUM * p;
BIGNUM * g;

p = BN_new();
g = BN_new();

if ((dh=DH_new()) == NULL) return(NULL);
dh->p=BN_bin2bn(dh1024_p,sizeof(dh1024_p),NULL);
dh->g=BN_bin2bn(dh1024_g,sizeof(dh1024_g),NULL);
if ((dh->p == NULL) || (dh->g == NULL))
p=BN_bin2bn(dh1024_p,sizeof(dh1024_p),NULL);
g=BN_bin2bn(dh1024_g,sizeof(dh1024_g),NULL);
if (1!=DH_set0_pqg(dh, p, NULL, g))
{ DH_free(dh); return(NULL); }
return(dh);
}
Expand Down

0 comments on commit fa8b33c

Please sign in to comment.