a.) Anyone who joins Freemasonry automatically incurs excommunication, which is simpliciter reserved to the Apostolic See.
The connection to Freemasonry is that one can be registered as a member. A special rite for reception is not required to incite excommunication. It is also not necessary for someone to take part in the Masonic meetings.
A freemason who wants to reconcile himself to the Church can only obtain the acquittal if he is completely separated from Freemasonry and removed from the membership list. He also has to promise never to pay a contribution, nor to participate in meetings of the lodge brothers. As far as possible, such a freemason must hand over all badges, books and documents to the ecclesiastical superior or his delegate. Furthermore, he must also make reparation for the offense as much as possible.
(b) The same punishment as the Freemasons fall into those who join a similar union which fights or agitates against the Church or the legitimate state power.
Because it must be an association similar to that of Freemasonry, the organization (but not the members) must be secret, as the members must observe silence about the structure, purpose, and means of the association. It is not, however, required that they should commit themselves by an oath.
A society fosters or acts against the Church, if it (perhaps among other good purposes) has the purpose of combating the Church, its authority, its powers, rights, privileges, etc., or its offices (not certain persons for personal reasons) ,
An organization fights against the powers of the state if, like the nihilists and anarchists, they want to eliminate any state authority or even to eliminate the existing state form, by revolution. But it does not belong here to the political parties who want to gain political power by law and then to change the state form. - It remains the same whether the association mentioned publicly or secretly to agitate against or strangle the Church or state.
Canon 2335 CIC, quoted from P. Heribert Jone OFM Cap .: Book of Canon Law. Explanation of canons, III. Vol. Litigation and Criminal Law. 1940, Paderborn.