Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Merlode11/pronote-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlode11 committed Dec 3, 2023
2 parents 3a7338a + f251665 commit e610c19
Show file tree
Hide file tree
Showing 10 changed files with 2,295 additions and 2,280 deletions.
13 changes: 11 additions & 2 deletions bin/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ async function student()
const discussions = await session.discussions();
const seeDiscussion = discussions.length ? await session.seeDiscussion(discussions[0]) : null;

const timetable = await session.timetable(from, to);
const params = session.params;
const user = session.user;


return {
name: session.user.name,
Expand All @@ -62,7 +66,8 @@ async function student()

marks, evaluations, absences,
infos, contents, homeworks, menu, files,
report, recipients, discussions, seeDiscussion
report, recipients, discussions, seeDiscussion, timetable,
params, user
};
}

Expand All @@ -87,13 +92,17 @@ async function parent()
const menu = await session.menu(student, from, to);
const files = await session.files(student);

const params = session.params;
const user = session.user;

students.push({
name: student.name,
studentClass: student.studentClass.name,
avatar: student.avatar,

timetable, marks, evaluations, absences,
infos, contents, homeworks, menu, files
infos, contents, homeworks, menu, files,
params, user
});
}

Expand Down
4,512 changes: 2,253 additions & 2,259 deletions index.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start": "node ./bin/server.js",
"lint": "eslint src/* bin/* index.js",
"check": "eslint --fix src/* bin/* index.js",
"test": "eslint src/* bin* index.js && node ./bin/test.js"
"test": "eslint src/* bin/* index.js && node ./bin/test.js"
},
"keywords": [
"pronote",
Expand Down
5 changes: 1 addition & 4 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ async function login(url, username, password, cas, account)
type: account,

disableAES: !!start.sCrA,
disableCompress: !!start.sCoA,

keyModulus: start.MR,
keyExponent: start.ER
disableCompress: !!start.sCoA
})

session.params = await getParams(session);
Expand Down
20 changes: 14 additions & 6 deletions src/cipher.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const forge = require('node-forge');
const pako = require('pako');

function initCipher(session, keyModulus, keyExponent)
// eslint-disable-next-line max-len
const RSA_1024_MODULO = 'B99B77A3D72D3A29B4271FC7B7300E2F791EB8948174BE7B8024667E915446D4EEA0C2424B8D1EBF7E2DDFF94691C6E994E839225C627D140A8F1146D1B0B5F18A09BBD3D8F421CA1E3E4796B301EEBCCF80D81A32A1580121B8294433C38377083C5517D5921E8A078CDC019B15775292EFDA2C30251B1CCABE812386C893E5';
const RSA_1024_EXPONENT = '65537'

function initCipher(session)
{
session.aesIV = generateIV();

session.publicKey = forge.pki.rsa.setPublicKey(
new forge.jsbn.BigInteger(keyModulus, 16),
new forge.jsbn.BigInteger(keyExponent, 16)
new forge.jsbn.BigInteger(RSA_1024_MODULO, 16),
new forge.jsbn.BigInteger(RSA_1024_EXPONENT, 10)
);
}

Expand Down Expand Up @@ -68,7 +72,8 @@ function createCipher(session, key, decipher, disableIV = false)
}

const cipher = forge.cipher[decipher ? 'createDecipher' : 'createCipher']('AES-CBC', md5(key));
const iv = disableIV ? forge.util.createBuffer('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') : md5(session.aesIV);
const iv = disableIV ? forge.util.createBuffer('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
: md5(session.aesIV);

cipher.start({ iv });

Expand All @@ -92,12 +97,15 @@ function inflate(data)

function generateIV()
{
return new forge.util.ByteBuffer(forge.random.generate(16));
return new forge.util.ByteBuffer(forge.random.getBytes(16));
}

function getUUID(session, iv)
{
return forge.util.encode64(session.publicKey.encrypt(iv.bytes()), 64);
if (session.disableAES) {
return forge.util.encode64(iv.bytes());
}
return forge.util.encode64(session.publicKey.encrypt(iv.bytes()));
}

function getLoginKey(username, password, scramble, fromCas)
Expand Down
5 changes: 4 additions & 1 deletion src/data/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const FileTypes = {
1: 'file'
}

function getFileURL(session, { id, name, type })
function getFileURL(session, { id, name, type, url })
{
const fileID = cipher(session, JSON.stringify(toPronote({ id, type })));
const fileName = encodeURIComponent(encodeURIComponent(name)); // *Clown emoji*

if (FileTypes[type] === 'link') {
if (url) {
return url;
}
return session.server + EXTERNAL_FILES_FOLDER + fileID + '/link?Session=' + session.id;
}
return session.server + EXTERNAL_FILES_FOLDER + fileID + '/' + fileName + '?Session=' + session.id;
Expand Down
7 changes: 6 additions & 1 deletion src/fetch/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ async function files(session, user) {
time: parseDate(file.date.V),
subject: subjects[file.matiere.V.N],
name: file.ressource.V.L,
url: getFileURL(session, { id: file.ressource.V.N, name: file.ressource.V.L, type: file.ressource.V.G }),
url: getFileURL(session, {
id: file.ressource.V.N,
name: file.ressource.V.L,
type: file.ressource.V.G,
url: file.ressource.V.url
}),
type: file.ressource.V.G
}, 'subject', 'name'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/fetch/pronote/homeworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ async function getHomeworks(session, user, fromWeek = 1, toWeek = null)
difficultyLevel: niveauDifficulte,
duration: duree,
color: CouleurFond,
files: parse(ListePieceJointe),
files: parse(ListePieceJointe)
}));
for (let i = 0; i < result.length; i++) { // Add markAs function to each homework
result[i].markAs = async done => {
await markHomeworkAs(session, user, result[i].id, done)
};
}d
}

return result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/fetch/pronote/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function getUser(session)
country: Coordonnees.Pays,
website: Coordonnees.SiteInternet
})),
userSettings: (({ version, EDT, theme, Communication }) => ({
userSettings: (({ version, EDT, Communication }) => ({
version,
timetable: {
displayCanceledLessons: EDT.afficherCoursAnnules,
Expand All @@ -38,7 +38,6 @@ async function getUser(session)
daysInTimetable: EDT.nbJoursEDT,
sequenceCount: EDT.nbSequences
},
theme: theme.theme,
unreadDiscussions: Communication.DiscussionNonLues
}))(user.parametresUtilisateur),
sessionAuthorizations: {
Expand Down
4 changes: 2 additions & 2 deletions src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const REQUESTS = {

class PronoteSession
{
constructor({ serverURL, sessionID, type, disableAES, disableCompress, keyModulus, keyExponent })
constructor({ serverURL, sessionID, type, disableAES, disableCompress })
{
this.id = ~~sessionID;
this.server = serverURL;
Expand All @@ -37,7 +37,7 @@ class PronoteSession
this.disableAES = disableAES;
this.disableCompress = disableCompress;

initCipher(this, keyModulus, keyExponent);
initCipher(this);

this.request = -1;
this.isKeptAlive = false;
Expand Down

0 comments on commit e610c19

Please sign in to comment.