Tuesday, June 6, 2017

Decrypt jwt token Authorization bearer

uppose that I response an encrypted access token to the user in web api response, which the user use it to access api in Authorization: Bearer header. Lets Assume that the user now has access token "abc". And JwtAuthorizationBearer now accepts token unencrypted token "def". But i would like it to accept the authorization bearer validation when user post the encrypted access token "abc" back. How could it be done?
I have seen a function name OnRequestToken but not sure whether it is used for this case.

app.UseJwtBearerAuthentication(
    new JwtBearerAuthenticationOptions
    {
        AuthenticationMode = AuthenticationMode.Active,
        AllowedAudiences = new[] { audience },
        IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
        {
            new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
        },
        Provider = new OAuthBearerAuthenticationProvider
        {
            OnValidateIdentity = context =>
            {
                if (!string.IsNullOrEmpty(token))
                {
                    var notPadded = token.Split('.')[1];
                    var padded = notPadded.PadRight(notPadded.Length + (4 - notPadded.Length % 4) % 4, '=');
                    var urlUnescaped = padded.Replace('-', '+').Replace('_', '/');
                    var claimsPart = Convert.FromBase64String(urlUnescaped);

                    var obj = JObject.Parse(Encoding.UTF8.GetString(claimsPart, 0, claimsPart.Length));

                    // simple, not handling specific types, arrays, etc.
                    foreach (var prop in obj.Properties().AsJEnumerable())
                    {
                        if (!context.Ticket.Identity.HasClaim(prop.Name, prop.Value.Value()))
                        {
                            context.Ticket.Identity.AddClaim(new Claim(prop.Name, prop.Value.Value()));
                        }
                    }
                }

                return Task.FromResult(null);
            }
        }
    });
https://stackoverflow.com/questions/34197323/decrypt-jwt-token-authorization-bearer

Monday, June 5, 2017

URL ENCODE/DECODE

In the HTTP-Redirect binding (A SAML binding used for exchanging AuthNRequests, SAML Logout Requests and SAML Logout Responses) the SAML Message is sent as a HTTP GET parameter. This message must be url encoded before being sent.
Use this tool to URL encode and decode a SAML Message GET parameter. Paste a SAML Message and obtain its url-encoded version or paste an url-encoded SAML Message and obtain its plain-text version.

URL Encode

URL Decode


Hack a FITs Image Header

If you are familiar with the python programming language, you could use the astropy module to view and manipulate fits files. Say you want to view the header of the file 'image.fits', then you do:
from astropy.io.fits import getheader

header = getheader('image.fits') # Load the data
print header                     # Print the header to screen
If you want to modify a particular key of the header, you do:
header['key'] = 'new_key'
View .fits file
My personal favorite GUI for viewing '.fits' files is DS9. Once installed you can view a file by typing ds9 /path/to/file.fits. Alternatively you can just use the menu in the GUI to load the image. Once you load the image in the viewer, you can view the header information by using the very top menu bar and going to 'File -> Display Header'. Unfortunately, I dont believe you can modify the header in DS9.
Modify fits header
For modifying the fits header, I found the easiest is to use astropy (a python package). Since you're using Ubuntu you should be able to download it via apt-get, so hopefully pretty easily. To actually edit the fits header, you can do the following in a python script, or from the interpreter (here's some additional help):
# Import the astropy fits tools
from astropy.io import fits

# Open the file header for viewing and load the header
hdulist = fits.open('yourfile.fits')
header = hdulist[0].header

# Print the header keys from the file to the terminal
header.keys

# Modify the key called 'NAXIS1' to have a value of 100
header['NAXIS1'] = '100'

# Modify the key called 'NAXIS1' and give it a comment
header['NAXIS1'] = ('100','This value has been modified!')

# Add a new key to the header
header.set('NEWKEY','50.5')

# Save the new file
hdulist.writeto('MyNewFile.fits')

# Make sure to close the file
hdulist.close()
You could also throw this in a loop for multiple file manipulation.

Trump tariffs ( how this 145% @ChinaEmbPt answer back 2 @realDonaldTrump will hike the americans householders tax payments, in more than 1010%)

  https://www.realtor.com/news/trends/trump-tariffs-china-mortgage-rate-housing/