Created
December 1, 2014 00:32
-
-
Save formula1/62cef83c97de8557a912 to your computer and use it in GitHub Desktop.
Stuntman Node Psuedo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v8::Array convertAttribute(AuthAttrubutes pAttribute){ | |
Local<Object> ret = Object::New(); | |
ret->Set( | |
String::NewSymbol("user"), | |
v8::String::New(pAttribute.szUser) | |
); | |
ret->Set( | |
String::NewSymbol("realm"), | |
v8::String::New(pAttribute.szRealm) | |
); | |
ret->Set( | |
String::NewSymbol("nonce"), | |
v8::String::New(pAttribute.szNonce) | |
); | |
ret->Set( | |
String::NewSymbol("legacy_password"), | |
v8::String::New(pAttribute.szLegacyPassword) | |
); | |
ret->Set( | |
String::NewSymbol("message_integrity"), | |
v8::Boolean::New(pAttribute.fMessageIntegrityPresent) | |
); | |
return ret; | |
} | |
v8::Object convertResponse(AuthResponse pResponse){ | |
Local<Object> ret = Object::New(); | |
ret->Set( | |
String::NewSymbol("type"), | |
v8::Integer::New(pResponse.AuthResponseType) | |
); | |
ret->Set( | |
String::NewSymbol("credential_mechanism"), | |
v8::Integer::New(pResponse.authCredMech) | |
); | |
ret->Set( | |
String::NewSymbol("password"), | |
v8::String::New(pResponse.szPassword) | |
); | |
ret->Set( | |
String::NewSymbol("realm"), | |
v8::String::New(pResponse.szRealm) | |
); | |
ret->Set( | |
String::NewSymbol("nonce"), | |
v8::String::New(pResponse.szNonce) | |
); | |
return ret; | |
} | |
v8::Boolean runListeners(char* type, v8::Object pAuthAttributes){ | |
//http://izs.me/v8-docs/classv8_1_1Object.html | |
//Listeners is a hashmap | |
//Every value of a key in listeners is an Array of functions | |
v8::Array l = listeners->Get(type); | |
i = 0 | |
while ( i < l.Length()) { //http://izs.me/v8-docs/classv8_1_1Array.html | |
//http://izs.me/v8-docs/classv8_1_1Function.html | |
if(l->Get(i).Call(l,v8attr).toBoolean()->Value() == false){ | |
return false; | |
} | |
i++; | |
} | |
return true; | |
} | |
HRESULT CShortTermAuth::DoAuthCheck(AuthAttributes* pAuthAttributes, AuthResponse* pResponse){ | |
Local<Object> v8attr = ::convertAttribute(pAuthAttributes); | |
if(::runListeners("integrity",pAuthAttributes) == false){ | |
pResponse->responseType = Reject; | |
return S_OK; | |
} | |
if(::runListeners("auth",pAuthAttributes) == false){ | |
pResponse->responseType = Unauthorized; | |
return S_OK; | |
} | |
if(::runListeners("nonce",pAuthAttributes) == false){ | |
pResponse->responseType = StaleNonce; | |
return S_OK; | |
} | |
pResponse->responseType = AllowConditional; | |
return S_OK; | |
} | |
HRESULT CLongTermAuth::DoAuthCheck(AuthAttributes* pAuthAttributes, AuthResponse* pResponse) | |
{ | |
Local<Object> v8attr = ::convertAttribute(pAuthAttributes); | |
if(::runListeners("integrity",pAuthAttributes) == false){ | |
pResponse->responseType = Reject; | |
return S_OK; | |
} | |
if(::runListeners("auth",pAuthAttributes) == false){ | |
pResponse->responseType = Unauthorized; | |
return S_OK; | |
} | |
if(::runListeners("nonce",pAuthAttributes) == false){ | |
pResponse->responseType = StaleNonce; | |
return S_OK; | |
} | |
pResponse->responseType = AllowConditional; | |
return S_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment