Saturday, 4 June 2022

Tooltip component rendering but not visible, and it is not the z-index

import React, {useState, useEffect} from "react";

// The tooltip component is used for the Tooltip feature that is utilized 
const Tooltip = (couponProps) => {
    const { couponTheme, verticalMousePosition, data, showTooltip, isSwiper } = couponProps;
    const { TooltipText } = data;
    const [tooltipStyles, setTooltipStyles] = useState({display: 'none'});
    const [tooltipArrowStyles, setTooltipArrowStyles] = useState({display: 'none'});
    const { TooltipTextColor, TooltipBackgroundColor, TooltipFontSize } = couponTheme;

    // The useEffect hook will first define all the tooltip styling as objects. If the showTooltip variable defined in the parent element is active, render the tooltip.
    useEffect(() => {
        const topTooltipStyles = {
            bottom: '130%',
            left: '20%',
            right: '20%',
            width: '60%'
        }
    
        const topTooltipArrowStyles = {
            top: '100%',
            left: '50%',
            marginLeft: '-5px',
            borderColor: (TooltipBackgroundColor || 'black') + ' transparent transparent transparent',
            marginTop: 'unset'
        }
    
        const bottomTooltipStyles = {
            top: '125%',
            left: '20%',
            right: '20%',
            width: '60%'
        }
    
        const bottomTooltipArrowStyles = {
            bottom: '100%',
            left: '50%',
            marginLeft: '-5px',
            borderColor: 'transparent transparent ' + (TooltipBackgroundColor || 'black') + ' transparent'
        }

        if (showTooltip) {
            // The tooltip is configured to either render at the top of the interval bar or at the bottom of the interval bar. That is pased on where the mouse is located on the screen.
            let tooltipPositionStyles = {};
            let tooltipArrowPositionStyles = {};
            // If the vertical mouse position is less than 250px to the top, render the tooltip at the bottom under the parent componet. This means the user is at the top of the screen, so use the bottom styling.
            if (verticalMousePosition < 250 || isSwiper) {
                // This way, the tooltip will not be cut of from the top of the screen.
                tooltipPositionStyles = bottomTooltipStyles;
                tooltipArrowPositionStyles = bottomTooltipArrowStyles;
            // Else, that means the user is not at the top of the screen
            } else {
                tooltipPositionStyles = topTooltipStyles;
                tooltipArrowPositionStyles = topTooltipArrowStyles;
            }

            const tooltipArrowStylesObj = {
                content: ' ',
                position: 'absolute',
                borderWidth: '5px',
                borderStyle: 'solid',
                ...tooltipArrowPositionStyles
            }
            
            const tooltipStylesObj = {
                position: 'absolute',
                color: TooltipTextColor || 'white',
                background: TooltipBackgroundColor || 'black',
                padding: '10px',
                borderRadius: '10px',
                zIndex: '5000',
                textAlign: 'center',
                ...tooltipPositionStyles
            }

            // Set all of the arrow styles after determining if the tooltip is on top or on bottom.
            setTooltipArrowStyles(tooltipArrowStylesObj);
            setTooltipStyles(tooltipStylesObj);

        } else {
            // If the showTooltip variable is false, hide the tooltip.
            setTooltipArrowStyles({});
            setTooltipStyles({display: 'none'});
        }
    }, [showTooltip, verticalMousePosition, TooltipBackgroundColor, TooltipTextColor, isSwiper])

    return (
        <>{TooltipText !== undefined && TooltipText.trim() !== '' && TooltipText !== 'None' && TooltipText !== 'Inset Tooltip Text Here' && showTooltip ? 
            <div className='TooltipDiv' style={tooltipStyles}>
                <span className="ToolTipText" style=>{TooltipText}</span>
                <span className="ToolTipArrow" style={tooltipArrowStyles}></span>
            </div> 
        : null}</>
    );
}

export default Tooltip;

So the code is passed the vertical mouse position as a prop and if the mouse is within 250 from the top of the page the tooltip is rendered below the component hovered. It all works fine if the component renders above and the mouse is lower down the page because there is nothing above to obstruct the tooltip, but when the component renders below, with bottomTooltipStyles, it is absolutely positioned but the issue is it is rendering behind another component. My gut said it was obviously the z-index, but this tooltip has a zIndex of 5000 which is significantly larger than the next largest z-index on the page at 60. Checking google chrome dev tools, the styles are all appropriate, the component renders, but it is still somehow behind/hidden behind another component no matter what I do. Any ideas would be greatly appreciated!! Thanks in advance!

So my question can also be asked like, "Is there a css property that would cause an element to render 'above' (over) another element that has an arbitrarily high z-index?"

enter image description here



from Tooltip component rendering but not visible, and it is not the z-index

Android project not obfuscating

I want to obfuscate my android code, I have set minifienable true and setup proguard file, but after generating apk and decompile, the code is not obfuscated. This is my proguard :

my proguard file:

-dontwarn com.huawei.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.javax.net.ssl.*
-dontwarn org.openjsse.net.ssl.OpenJSSE

my build.gradle file

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug{
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }



from Android project not obfuscating

rsa encryption with flask and javascript

I'm trying to encrypt the data twice with rsa public keys, I'm getting the following error in python,

Traceback (most recent call last):
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app.py", line 39, in register_user
    first_encrypted = client_key_decrypter.decrypt(data['cipher'])
  File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/Crypto/Cipher/PKCS1_OAEP.py", line 167, in decrypt
    raise ValueError("Ciphertext with incorrect length.")
ValueError: Ciphertext with incorrect length.

What I'm trying to do is

generate the public and private keys in flask,

generate the client public and private keys to use unique to each call,

encrypt the data client side using jsencrypt,

decrypt the data server side using pycryptodome

here's my code in app.py

from flask import Flask
from flask import render_template
from flask import request
import Crypto
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from Crypto import Random
from base64 import *

application = Flask(__name__, static_url_path='/static')
random_generator = Random.new().read
key = RSA.generate(2048, random_generator) #generate public and private keys

@application.route("/")
def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

@application.route("/register")
def register():
    crypto_key = key.publickey().export_key()
    client_random_generator = Random.new().read
    client_key = RSA.generate(4096, client_random_generator) #generate for client-side encryption
    print(client_key)
    return render_template('register.html', 
        serverCrypto = crypto_key.decode("utf-8"),
        clientCrypto = client_key.publickey().export_key().decode("utf-8"), 
        randomName1 = client_key.export_key().decode("utf-8"), 
        randomName2 = None, 
        randomName3 = None)

@application.route("/users", methods=['POST'])
def register_user():
    error = None
    if request.method == "POST":
        data = request.get_json()
        print(data)
        client_key = RSA.importKey(data['clientPrivateKey'])
        client_key_decrypter = PKCS1_OAEP.new(client_key)
        first_encrypted = client_key_decrypter.decrypt(data['cipher'])
        server_key = PKCS1_OAEP.new(key.export_key())
        second_encrypted = server_key.decrypt(first_encrypted)
        print(second_encrypted)
    return render_template('login.html', error=error)

@application.route("/crypto", methods=['POST'])
def get_crypto():
    if request.method == "POST":
        return None

if __name__ == "__main__":
    application.run(ssl_context=('cert.pem', 'key.pem'))

my html code

<!DOCTYPE html>
<html>
<head>
    <title>Demo!</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.min.js"></script>
    <script type="text/javascript" src="/static/js/register.js"></script>
    <style type="text/css">
            input { margin-right: 100% }
        </style>
</head>
<body>
<h2>Register</h2>
<form id="register">
    <label>Username: <input name="username" type="text"
                            id="username">
    </label>
    <label>Password: <input name="password" type="password"
                            id="password">
    </label>
    <input type="hidden" name="serverCrypto" id="serverCrypto" value=""/>
    <input type="hidden" name="clientCrypto" id="clientCrypto" value=""/>
    <input type="hidden" name="randomName1" id="randomName1" value=""/>
    <input type="hidden" name="randomName2" id="randomName2" value=""/>
    <input type="hidden" name="randomName3" id="randomName3" value=""/>
    <button type="register">Register</button>
</form>
</body>
</html>

and my javascript code

const apiUrl = 'https://localhost:5000';


function register(username, password, serverCrypto, clientCrypto, randomName1) {
    let data = {"username": username, "passwword": password}

    const encrypt = new JSEncrypt();
    encrypt.setPublicKey(serverCrypto);
    var encrypted = encrypt.encrypt(JSON.stringify(data));
    console.log(encrypted); // shows up as false
    encrypt.setPublicKey(clientCrypto);
    encrypted = encrypt.encrypt(encrypted);
    console.log(encrypted);
    dataToSend = {"cipher": encrypted, "clientPrivateKey": randomName1};

    fetch(apiUrl + '/users', {
        method: 'POST',
        body: JSON.stringify(dataToSend),
        headers: {
            'Content-Type': 'application/json',
        }
    })
    .then(res => {
       if (res.ok) {
         res.json().then(json => {
            console.log(json);
         });
       }
    })
    .catch(error => console.error('Error logging in: ', error));
}

window.addEventListener('load', function(e) {
    document.getElementById('register')
        .addEventListener('submit', processRegisterSubmit);
});

function processRegisterSubmit(e) {
    e.preventDefault();

    let username = document.getElementById('username').value;
    let password = document.getElementById('password').value;
    let serverCrypto = document.getElementById('serverCrypto').value;
    let clientCrypto = document.getElementById('clientCrypto').value;
    let randomName1 = document.getElementById('randomName1').value;
    let randomName2 = document.getElementById('randomName2').value;
    let randomName3 = document.getElementById('randomName3').value;
    

    register(username, password, serverCrypto, clientCrypto, randomName1);
    return false;
}



from rsa encryption with flask and javascript