serial number and cert hash route
All checks were successful
Build and Test / account (push) Successful in 3m16s
All checks were successful
Build and Test / account (push) Successful in 3m16s
This commit is contained in:
parent
f32e69be99
commit
9bf06fffd6
12 changed files with 122 additions and 59 deletions
28
.sqlx/query-0ef5f08a84d6864291cb6125610d9d3e1961530ae963f9ab5442482d81228590.json
generated
Normal file
28
.sqlx/query-0ef5f08a84d6864291cb6125610d9d3e1961530ae963f9ab5442482d81228590.json
generated
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "select serial from certificates where hash = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "serial",
|
||||
"type_info": "Varchar",
|
||||
"origin": {
|
||||
"Table": {
|
||||
"table": "certificates",
|
||||
"name": "serial"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Bytea"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "0ef5f08a84d6864291cb6125610d9d3e1961530ae963f9ab5442482d81228590"
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT nextval('pid_counter') as pid",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "pid",
|
||||
"type_info": "Int8",
|
||||
"origin": "Expression"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": []
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "3c9b1695f8ae49e4308c048de98c1c262351465b6f102e98912f67442a1f54d9"
|
||||
}
|
||||
|
|
@ -68,6 +68,17 @@
|
|||
"name": "expires"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "cert_hash",
|
||||
"type_info": "Bytea",
|
||||
"origin": {
|
||||
"Table": {
|
||||
"table": "tokens",
|
||||
"name": "cert_hash"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
|
@ -83,7 +94,8 @@
|
|||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "48710e0b87742cc3fef816b3c95604095f71324011e7093ec37af15da8c158f4"
|
||||
|
|
|
|||
|
|
@ -68,6 +68,17 @@
|
|||
"name": "expires"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "cert_hash",
|
||||
"type_info": "Bytea",
|
||||
"origin": {
|
||||
"Table": {
|
||||
"table": "tokens",
|
||||
"name": "cert_hash"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
|
@ -83,7 +94,8 @@
|
|||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "9d3cee43a86cead9a6d078abc1266fc2a97ac6e25a9733d1d20faf555c67abe1"
|
||||
|
|
|
|||
15
.sqlx/query-beeeea07993ba8daac1e43c985e8c840f66eec4e5458d3709c0e0f09afe51377.json
generated
Normal file
15
.sqlx/query-beeeea07993ba8daac1e43c985e8c840f66eec4e5458d3709c0e0f09afe51377.json
generated
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "update certificates set serial = $1 where hash = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Bytea"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "beeeea07993ba8daac1e43c985e8c840f66eec4e5458d3709c0e0f09afe51377"
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT EXISTS(select 1 from users where pid = $1)",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "exists",
|
||||
"type_info": "Bool",
|
||||
"origin": "Expression"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "c8d50662530cac49c4261fb321cd15f9e4bafdfca12d2130a873d44a88dd435b"
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "insert into tokens (token_type, pid, title_id)\n values ($1, $2, $3) returning token_id, random",
|
||||
"query": "insert into tokens (token_type, pid, title_id, cert_hash)\n values ($1, $2, $3, $4) returning token_id, random",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
|
|
@ -30,7 +30,8 @@
|
|||
"Left": [
|
||||
"Int4",
|
||||
"Int4",
|
||||
"Varchar"
|
||||
"Varchar",
|
||||
"Bytea"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
|
|
@ -38,5 +39,5 @@
|
|||
false
|
||||
]
|
||||
},
|
||||
"hash": "e5a2f7f28c3d7b9524d3dce48a9e47d6180ff634ebf59f3a1efd92b797170ac2"
|
||||
"hash": "d8298703381f0e220bdbe122dbdc4dc5cd7ae99fac34ae16023f9a6a701857c9"
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
use rocket::serde::json::Json;
|
||||
use rocket::{post, FromForm, State};
|
||||
use rocket::form::Form;
|
||||
use rocket::futures::TryFutureExt;
|
||||
use rocket::http::Status;
|
||||
use crate::account::account::Auth;
|
||||
use crate::json_api::oauth::generate_token::TokenRequest;
|
||||
use crate::nnid::people::{build_oauth_profile, GetOwnOAuthProfileData};
|
||||
use crate::Pool;
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
|
@ -21,7 +17,7 @@ pub async fn ban_user(pool: &State<Pool>, auth: Auth<true>, request: Form<AdminR
|
|||
|
||||
log::info!("banning user {:?} from moderator {:?}", request.username, auth.username);
|
||||
|
||||
let row = sqlx::query!(
|
||||
let _row = sqlx::query!(
|
||||
"UPDATE users SET account_level = $1 WHERE username = $2",
|
||||
-1,
|
||||
request.username
|
||||
|
|
|
|||
40
src/json_api/users/console.rs
Normal file
40
src/json_api/users/console.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use rocket::serde::json::Json;
|
||||
use rocket::{get, State};
|
||||
use rocket::http::Status;
|
||||
use crate::account::account::Auth;
|
||||
use serde::Serialize;
|
||||
use crate::Pool;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ConsoleData {
|
||||
pub serial: String,
|
||||
pub cert_hash: String,
|
||||
}
|
||||
|
||||
#[get("/api/v2/users/@me/console")]
|
||||
pub async fn get_own_console(pool: &State<Pool>, auth: Auth<true>) -> Result<Json<ConsoleData>, (Status, &'static str)> {
|
||||
let hash = auth.1.ok_or((Status::BadRequest, "token needs cert hash"))?;
|
||||
|
||||
let row = sqlx::query!(
|
||||
"select serial from certificates where hash = $1",
|
||||
&hash[..]
|
||||
)
|
||||
.fetch_one(pool.inner())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!("failed to execute query: {:?}", e);
|
||||
(Status::InternalServerError, "error in database query")
|
||||
})?;
|
||||
|
||||
let hex_hash = hex::encode(hash);
|
||||
let serial = row.serial.ok_or((Status::BadRequest, "we had no serial"))?;
|
||||
|
||||
Ok(
|
||||
Json (
|
||||
ConsoleData {
|
||||
serial,
|
||||
cert_hash: hex_hash
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod profile;
|
||||
pub mod mii;
|
||||
pub mod delete;
|
||||
pub mod console;
|
||||
|
|
@ -119,6 +119,7 @@ async fn launch() -> _ {
|
|||
json_api::oauth::authorize::authorize_page,
|
||||
json_api::oauth::authorize::authorize_submit,
|
||||
json_api::admin::bans::ban_user,
|
||||
json_api::users::console::get_own_console,
|
||||
nnid::people::thing,
|
||||
// graphql::graphiql,
|
||||
// graphql::playground,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use crate::nnid::oauth::generate_token::token_type::NEX_TOKEN;
|
|||
use crate::xml::Xml;
|
||||
use log::{info, warn};
|
||||
use nex_account::grpc::Pid;
|
||||
use reqwest::header::SERVER;
|
||||
use rocket::http::Status;
|
||||
use rocket::request::{FromRequest, Outcome, Request};
|
||||
use rocket::{State, async_trait, get};
|
||||
|
|
@ -74,18 +73,20 @@ pub async fn store_or_check_serial(pool: &Pool, serial: &str, cert_hash: [u8; 32
|
|||
};
|
||||
|
||||
let Some(stored_serial) = res.serial else {
|
||||
query!(
|
||||
let _row = query!(
|
||||
"update certificates set serial = $1 where hash = $2",
|
||||
serial,
|
||||
&cert_hash[..]
|
||||
);
|
||||
).execute(pool)
|
||||
.await
|
||||
.ok();
|
||||
return true;
|
||||
};
|
||||
|
||||
serial == stored_serial
|
||||
}
|
||||
|
||||
struct Serial(String);
|
||||
pub struct Serial(pub String);
|
||||
|
||||
#[async_trait]
|
||||
impl<'r> FromRequest<'r> for Serial {
|
||||
|
|
|
|||
Loading…
Reference in a new issue